JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Helper class that is used to flatten JSON structure when using
* "external type id" (see {@link com.fasterxml.jackson.annotation.JsonTypeInfo.As#EXTERNAL_PROPERTY}).
* This is needed to store temporary state and buffer tokens, as the structure is
* rearranged a bit so that actual type deserializer can resolve type and
* finalize deserialization.
*/
public class ExternalTypeHandler
{
private final ExtTypedProperty[] _properties;
private final HashMap<String, Integer> _nameToPropertyIndex;
private final String[] _typeIds;
private final TokenBuffer[] _tokens;
protected ExternalTypeHandler(ExtTypedProperty[] properties,
HashMap<String, Integer> nameToPropertyIndex,
String[] typeIds, TokenBuffer[] tokens)
{
_properties = properties;
_nameToPropertyIndex = nameToPropertyIndex;
_typeIds = typeIds;
_tokens = tokens;
}
protected ExternalTypeHandler(ExternalTypeHandler h)
{
_properties = h._properties;
_nameToPropertyIndex = h._nameToPropertyIndex;
int len = _properties.length;
_typeIds = new String[len];
_tokens = new TokenBuffer[len];
}
/**
* Method called to start collection process by creating non-blueprint
* instances.
*/
public ExternalTypeHandler start() {
return new ExternalTypeHandler(this);
}
/**
* Method called to see if given property/value pair is an external type
* id; and if so handle it. This is <b>only</b> to be called in case
* containing POJO has similarly named property as the external type id;
* otherwise {@link #handlePropertyValue} should be called instead.
*/
public boolean handleTypePropertyValue(JsonParser p, DeserializationContext ctxt,
String propName, Object bean)
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
throws IOException
{
Integer I = _nameToPropertyIndex.get(propName);
if (I == null) {
return false;
}
int index = I.intValue();
ExtTypedProperty prop = _properties[index];
if (!prop.hasTypePropertyName(propName)) {
return false;
}
String typeId = p.getText();
// note: can NOT skip child values (should always be String anyway)
boolean canDeserialize = (bean != null) && (_tokens[index] != null);
// Minor optimization: deserialize properties as soon as we have all we need:
if (canDeserialize) {
_deserializeAndSet(p, ctxt, bean, index, typeId);
// clear stored data, to avoid deserializing+setting twice:
_tokens[index] = null;
} else {
_typeIds[index] = typeId;
}
return true;
}
/**
* Method called to ask handler to handle value of given property,
* at point where parser points to the first token of the value.
* Handling can mean either resolving type id it contains (if it matches type
* property name), or by buffering the value for further use.
*
* @return True, if the given property was properly handled
*/
public boolean handlePropertyValue(JsonParser p, DeserializationContext ctxt,
String propName, Object bean) throws IOException
{
Integer I = _nameToPropertyIndex.get(propName);
if (I == null) {
return false;
}
int index = I.intValue();
ExtTypedProperty prop = _properties[index];
boolean canDeserialize;
if (prop.hasTypePropertyName(propName)) {
_typeIds[index] = p.getText();
p.skipChildren();
canDeserialize = (bean != null) && (_tokens[index] != null);
} else {
@SuppressWarnings("resource")
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.copyCurrentStructure(p);
_tokens[index] = tokens;
canDeserialize = (bean != null) && (_typeIds[index] != null);
}
/* Minor optimization: let's deserialize properties as soon as
* we have all pertinent information:
*/
if (canDeserialize) {
String typeId = _typeIds
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>[index];
// clear stored data, to avoid deserializing+setting twice:
_typeIds[index] = null;
_deserializeAndSet(p, ctxt, bean, index, typeId);
_tokens[index] = null;
}
return true;
}
/**
* Method called after JSON Object closes, and has to ensure that all external
* type ids have been handled.
*/
@SuppressWarnings("resource")
public Object complete(JsonParser p, DeserializationContext ctxt, Object bean)
throws IOException
{
for (int i = 0, len = _properties.length; i < len; ++i) {
String typeId = _typeIds[i];
if (typeId == null) {
TokenBuffer tokens = _tokens[i];
// let's allow missing both type and property (may already have been set, too)
// but not just one
if (tokens == null) {
continue;
}
// [databind#118]: Need to mind natural types, for which no type id
// will be included.
JsonToken t = tokens.firstToken();
if (t != null && t.isScalarValue()) {
JsonParser buffered = tokens.asParser(p);
buffered.nextToken();
SettableBeanProperty extProp = _properties[i].getProperty();
Object result = TypeDeserializer.deserializeIfNatural(buffered, ctxt, extProp.getType());
if (result != null) {
extProp.set(bean, result);
continue;
}
// 26-Oct-2012, tatu: As per [databind#94], must allow use of 'defaultImpl'
if (!_properties[i].hasDefaultType()) {
ctxt.reportMappingException("Missing external type id property '%s'",
_properties[i].getTypePropertyName());
} else {
typeId = _properties[i].getDefaultTypeId();
}
}
} else if (_tokens[i] == null) {
SettableBeanProperty prop = _properties[i].getProperty();
ctxt.reportMappingException("Missing property '%s' for external type id '%s'",
prop.getName(), _properties[i].getTypePropertyName());
}
_deserializeAndSet(p, ctxt, bean, i, typeId);
}
return bean;
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> /**
* Variant called when creation of the POJO involves buffering of creator properties
* as well as property-based creator.
*/
public Object complete(JsonParser p, DeserializationContext ctxt,
PropertyValueBuffer buffer, PropertyBasedCreator creator)
throws IOException
{
// first things first: deserialize all data buffered:
final int len = _properties.length;
Object[] values = new Object[len];
for (int i = 0; i < len; ++i) {
String typeId = _typeIds[i];
final ExtTypedProperty extProp = _properties[i];
if (typeId == null) {
// let's allow missing both type and property (may already have been set, too)
if (_tokens[i] == null) {
continue;
}
// but not just one
// 26-Oct-2012, tatu: As per [databind#94], must allow use of 'defaultImpl'
if (!extProp.hasDefaultType()) {
ctxt.reportMappingException("Missing external type id property '%s'",
extProp.getTypePropertyName());
} else {
typeId = extProp.getDefaultTypeId();
}
} else if (_tokens[i] == null) {
SettableBeanProperty prop = extProp.getProperty();
ctxt.reportMappingException("Missing property '%s' for external type id '%s'",
prop.getName(), _properties[i].getTypePropertyName());
}
values[i] = _deserialize(p, ctxt, i, typeId);
final SettableBeanProperty prop = extProp.getProperty();
// also: if it's creator prop, fill in
if (prop.getCreatorIndex() >= 0) {
buffer.assignParameter(prop, values[i]);
// [databind#999] And maybe there's creator property for type id too?
SettableBeanProperty typeProp = extProp.getTypeProperty();
// for now, should only be needed for creator properties, too
if ((typeProp != null) && (typeProp.getCreatorIndex() >= 0)) {
buffer.assignParameter(typeProp, typeId);
}
}
}
Object bean = creator.build(ctxt, buffer);
// third: assign non-creator properties
for (int i = 0; i
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> < len; ++i) {
SettableBeanProperty prop = _properties[i].getProperty();
if (prop.getCreatorIndex() < 0) {
prop.set(bean, values[i]);
}
}
return bean;
}
@SuppressWarnings("resource")
protected final Object _deserialize(JsonParser p, DeserializationContext ctxt,
int index, String typeId) throws IOException
{
JsonParser p2 = _tokens[index].asParser(p);
JsonToken t = p2.nextToken();
// 29-Sep-2015, tatu: As per [databind#942], nulls need special support
if (t == JsonToken.VALUE_NULL) {
return null;
}
TokenBuffer merged = new TokenBuffer(p, ctxt);
merged.writeStartArray();
merged.writeString(typeId);
merged.copyCurrentStructure(p2);
merged.writeEndArray();
// needs to point to START_OBJECT (or whatever first token is)
JsonParser mp = merged.asParser(p);
mp.nextToken();
return _properties[index].getProperty().deserialize(mp, ctxt);
}
@SuppressWarnings("resource")
protected final void _deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object bean, int index, String typeId) throws IOException
{
/* Ok: time to mix type id, value; and we will actually use "wrapper-array"
* style to ensure we can handle all kinds of JSON constructs.
*/
JsonParser p2 = _tokens[index].asParser(p);
JsonToken t = p2.nextToken();
// 29-Sep-2015, tatu: As per [databind#942], nulls need special support
if (t == JsonToken.VALUE_NULL) {
_properties[index].getProperty().set(bean, null);
return;
}
TokenBuffer merged = new TokenBuffer(p, ctxt);
merged.writeStartArray();
merged.writeString(typeId);
merged.copyCurrentStructure(p2);
merged.writeEndArray();
// needs to point to START_OBJECT (or whatever first token is)
JsonParser mp = merged.asParser(p);
mp.nextToken();
_properties[index].getProperty
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>().deserializeAndSet(mp, ctxt, bean);
}
/*
/**********************************************************
/* Helper classes
/**********************************************************
*/
* @since 2.8
*/
private SettableBeanProperty _typeProperty;
public ExtTypedProperty(SettableBeanProperty property, TypeDeserializer typeDeser)
{
_property = property;
_typeDeserializer = typeDeser;
_typePropertyName = typeDeser.getPropertyName();
}
/**
* @since 2.8
*/
public void linkTypeProperty(SettableBeanProperty p) {
_typeProperty = p;
}
public boolean hasTypePropertyName(String n) {
return n.equals(_typePropertyName);
}
public boolean hasDefaultType() {
return _typeDeserializer.getDefaultImpl() != null;
}
/**
* Specialized called when we need to expose type id of `defaultImpl` when
* serializing: we may need to expose it for assignment to a property, or
* it may be requested as visible for some other reason.
*/
public String getDefaultTypeId() {
Class<?> defaultType = _typeDeserializer.getDefaultImpl();
if (defaultType == null) {
return null;
}
return _typeDeserializer.getTypeIdResolver().idFromValueAndType(null, defaultType);
}
public String getTypePropertyName() { return _typePropertyName; }
public SettableBeanProperty getProperty() {
return _property;
}
/**
* @since 2.8
*/
public SettableBeanProperty getTypeProperty() {
return _typeProperty;
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>serializationShape;
/*
/**********************************************************
/* Configuration for creating value instance
/**********************************************************
*/
/**
* Object that handles details of constructing initial
* bean value (to which bind data to), unless instance
* is passed (via updateValue())
*/
protected final ValueInstantiator _valueInstantiator;
/**
* Deserializer that is used iff delegate-based creator is
* to be used for deserializing from JSON Object.
*/
protected JsonDeserializer<Object> _delegateDeserializer;
/**
* Deserializer that is used iff array-delegate-based creator
* is to be used for deserializing from JSON Object.
*/
protected JsonDeserializer<Object> _arrayDelegateDeserializer;
/**
* If the bean needs to be instantiated using constructor
* or factory method
* that takes one or more named properties as argument(s),
* this creator is used for instantiation.
* This value gets resolved during general resolution.
*/
protected PropertyBasedCreator _propertyBasedCreator;
/**
* Flag that is set to mark "non-standard" cases; where either
* we use one of non-default creators, or there are unwrapped
* values to consider.
*/
protected boolean _nonStandardCreation;
/**
* Flag that indicates that no "special features" whatsoever
* are enabled, so the simplest processing is possible.
*/
protected boolean _vanillaProcessing;
/*
/**********************************************************
/* Property information, setters
/**********************************************************
*/
/**
* Mapping of property names to properties, built when all properties
* to use have been successfully resolved.
*/
final protected BeanPropertyMap _beanProperties;
/**
* List of {@link ValueInjector}s, if any injectable values are
* expected by the bean; otherwise null.
* This includes injectors used for injecting values via setters
* and fields, but not ones passed through constructor parameters.
*/
final protected ValueInjector[] _injectables;
/**
* Fallback setter used for handling any properties that are not
* mapped to regular setters. If setter is not null, it will be
* called once for each such property.
*/
protected SettableAnyProperty _anySetter;
/**
* In addition to properties that are set, we will also keep
* track of recognized but ignorable properties: these will
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> * be skipped without errors or warnings.
*/
final protected Set<String> _ignorableProps;
/**
* Flag that can be set to ignore and skip unknown properties.
* If set, will not throw an exception for unknown properties.
*/
final protected boolean _ignoreAllUnknown;
/**
* Flag that indicates that some aspect of deserialization depends
* on active view used (if any)
*/
final protected boolean _needViewProcesing;
/**
* We may also have one or more back reference fields (usually
* zero or one).
*/
final protected Map<String, SettableBeanProperty> _backRefs;
/*
/**********************************************************
/* Related handlers
/**********************************************************
*/
/**
* Lazily constructed map used to contain deserializers needed
* for polymorphic subtypes.
* Note that this is <b>only needed</b> for polymorphic types,
* that is, when the actual type is not statically known.
* For other types this remains null.
*/
protected transient HashMap<ClassKey, JsonDeserializer<Object>> _subDeserializers;
/**
* If one of properties has "unwrapped" value, we need separate
* helper object
*/
protected UnwrappedPropertyHandler _unwrappedPropertyHandler;
/**
* Handler that we need iff any of properties uses external
* type id.
*/
protected ExternalTypeHandler _externalTypeIdHandler;
/**
* If an Object Id is to be used for value handled by this
* deserializer, this reader is used for handling.
*/
protected final ObjectIdReader _objectIdReader;
/*
/**********************************************************
/* Life-cycle, construction, initialization
/**********************************************************
*/
/**
* Constructor used when initially building a deserializer
* instance, given a {@link BeanDeserializerBuilder} that
* contains configuration.
*/
protected BeanDeserializerBase(BeanDeserializerBuilder builder,
BeanDescription beanDesc,
BeanPropertyMap properties, Map<String, SettableBeanProperty> backRefs,
Set<String> ignorableProps, boolean ignoreAllUnknown,
boolean hasViews)
{
super(beanDesc.getType());
AnnotatedClass ac = beanDesc.getClassInfo();
_classAnnotations = ac.getAnnotations();
_beanType = beanDesc.getType();
_valueInstantiator = builder.getValueInstantiator
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>();
_beanProperties = properties;
_backRefs = backRefs;
_ignorableProps = ignorableProps;
_ignoreAllUnknown = ignoreAllUnknown;
_anySetter = builder.getAnySetter();
List<ValueInjector> injectables = builder.getInjectables();
_injectables = (injectables == null || injectables.isEmpty()) ? null
: injectables.toArray(new ValueInjector[injectables.size()]);
_objectIdReader = builder.getObjectIdReader();
_nonStandardCreation = (_unwrappedPropertyHandler != null)
|| _valueInstantiator.canCreateUsingDelegate()
|| _valueInstantiator.canCreateFromObjectWith()
|| !_valueInstantiator.canCreateUsingDefault()
;
// Any transformation we may need to apply?
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
_serializationShape = (format == null) ? null : format.getShape();
_needViewProcesing = hasViews;
_vanillaProcessing = !_nonStandardCreation
&& (_injectables == null)
&& !_needViewProcesing
// also, may need to reorder stuff if we expect Object Id:
&& (_objectIdReader == null)
;
}
protected BeanDeserializerBase(BeanDeserializerBase src) {
this(src, src._ignoreAllUnknown);
}
protected BeanDeserializerBase(BeanDeserializerBase src, boolean ignoreAllUnknown)
{
super(src._beanType);
_classAnnotations = src._classAnnotations;
_beanType = src._beanType;
_valueInstantiator = src._valueInstantiator;
_delegateDeserializer = src._delegateDeserializer;
_propertyBasedCreator = src._propertyBasedCreator;
_beanProperties = src._beanProperties;
_backRefs = src._backRefs;
_ignorableProps = src._ignorableProps;
_ignoreAllUnknown = ignoreAllUnknown;
_anySetter = src._anySetter;
_injectables = src._injectables;
_objectIdReader = src._objectIdReader;
_nonStandardCreation = src._nonStandardCreation;
_unwrappedPropertyHandler = src._unwrappedPropertyHandler;
_needViewProcesing = src._needViewProcesing;
_serializationShape = src._serializationShape;
_vanillaProcessing = src._vanillaProcessing;
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> }
protected BeanDeserializerBase(BeanDeserializerBase src, NameTransformer unwrapper)
{
super(src._beanType);
_classAnnotations = src._classAnnotations;
_beanType = src._beanType;
_valueInstantiator = src._valueInstantiator;
_delegateDeserializer = src._delegateDeserializer;
_propertyBasedCreator = src._propertyBasedCreator;
_backRefs = src._backRefs;
_ignorableProps = src._ignorableProps;
_ignoreAllUnknown = (unwrapper != null) || src._ignoreAllUnknown;
_anySetter = src._anySetter;
_injectables = src._injectables;
_objectIdReader = src._objectIdReader;
_nonStandardCreation = src._nonStandardCreation;
UnwrappedPropertyHandler uph = src._unwrappedPropertyHandler;
if (unwrapper != null) {
// delegate further unwraps, if any
if (uph != null) { // got handler, delegate
uph = uph.renameAll(unwrapper);
}
// and handle direct unwrapping as well:
_beanProperties = src._beanProperties.renameAll(unwrapper);
} else {
_beanProperties = src._beanProperties;
}
_unwrappedPropertyHandler = uph;
_needViewProcesing = src._needViewProcesing;
_serializationShape = src._serializationShape;
// probably adds a twist, so:
_vanillaProcessing = false;
}
public BeanDeserializerBase(BeanDeserializerBase src, ObjectIdReader oir)
{
super(src._beanType);
_classAnnotations = src._classAnnotations;
_beanType = src._beanType;
_valueInstantiator = src._valueInstantiator;
_delegateDeserializer = src._delegateDeserializer;
_propertyBasedCreator = src._propertyBasedCreator;
_backRefs = src._backRefs;
_ignorableProps = src._ignorableProps;
_ignoreAllUnknown = src._ignoreAllUnknown;
_anySetter = src._anySetter;
_injectables = src._injectables;
_nonStandardCreation = src._nonStandardCreation;
_unwrappedPropertyHandler = src._unwrappedPropertyHandler;
_needViewProcesing = src._needViewProcesing;
_serializationShape = src._serializationShape
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>;
// then actual changes:
_objectIdReader = oir;
if (oir == null) {
_beanProperties = src._beanProperties;
_vanillaProcessing = src._vanillaProcessing;
} else {
/* 18-Nov-2012, tatu: May or may not have annotations for id property;
* but no easy access. But hard to see id property being optional,
* so let's consider required at this point.
*/
ObjectIdValueProperty idProp = new ObjectIdValueProperty(oir, PropertyMetadata.STD_REQUIRED);
_beanProperties = src._beanProperties.withProperty(idProp);
_vanillaProcessing = false;
}
}
public BeanDeserializerBase(BeanDeserializerBase src, Set<String> ignorableProps)
{
super(src._beanType);
_classAnnotations = src._classAnnotations;
_beanType = src._beanType;
_valueInstantiator = src._valueInstantiator;
_delegateDeserializer = src._delegateDeserializer;
_propertyBasedCreator = src._propertyBasedCreator;
_backRefs = src._backRefs;
_ignorableProps = ignorableProps;
_ignoreAllUnknown = src._ignoreAllUnknown;
_anySetter = src._anySetter;
_injectables = src._injectables;
_nonStandardCreation = src._nonStandardCreation;
_unwrappedPropertyHandler = src._unwrappedPropertyHandler;
_needViewProcesing = src._needViewProcesing;
_serializationShape = src._serializationShape;
_vanillaProcessing = src._vanillaProcessing;
_objectIdReader = src._objectIdReader;
// 01-May-2016, tatu: [databind#1217]: Remove properties from mapping,
// to avoid them being deserialized
_beanProperties = src._beanProperties.withoutProperties(ignorableProps);
}
/**
* @since 2.8
*/
protected BeanDeserializerBase(BeanDeserializerBase src, BeanPropertyMap beanProps)
{
super(src._beanType);
_classAnnotations = src._classAnnotations;
_beanType = src._beanType;
_valueInstantiator = src._valueInstantiator;
_delegateDeserializer = src._delegateDeserializer;
_propertyBasedCreator =
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> src._propertyBasedCreator;
_beanProperties = beanProps;
_backRefs = src._backRefs;
_ignorableProps = src._ignorableProps;
_ignoreAllUnknown = src._ignoreAllUnknown;
_anySetter = src._anySetter;
_injectables = src._injectables;
_objectIdReader = src._objectIdReader;
_nonStandardCreation = src._nonStandardCreation;
_unwrappedPropertyHandler = src._unwrappedPropertyHandler;
_needViewProcesing = src._needViewProcesing;
_serializationShape = src._serializationShape;
_vanillaProcessing = src._vanillaProcessing;
}
@Override
public abstract JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper);
public abstract BeanDeserializerBase withObjectIdReader(ObjectIdReader oir);
public abstract BeanDeserializerBase withIgnorableProperties(Set<String> ignorableProps);
/**
* Mutant factory method that custom sub-classes must override; not left as
* abstract to prevent more drastic backwards compatibility problems.
*
* @since 2.8
*/
public BeanDeserializerBase withBeanProperties(BeanPropertyMap props) {
throw new UnsupportedOperationException("Class "+getClass().getName()
+" does not override `withBeanProperties()`, needs to");
}
/**
* Fluent factory for creating a variant that can handle
* POJO output as a JSON Array. Implementations may ignore this request
* if no such input is possible.
*
* @since 2.1
*/
protected abstract BeanDeserializerBase asArrayDeserializer();
/*
/**********************************************************
/* Validation, post-processing
/**********************************************************
*/
/**
* Method called to finalize setup of this deserializer,
* after deserializer itself has been registered.
* This is needed to handle recursive and transitive dependencies.
*/
@Override
public void resolve(DeserializationContext ctxt)
throws JsonMappingException
{
ExternalTypeHandler.Builder extTypes = null;
// if ValueInstantiator can use "creator" approach, need to resolve it here...
SettableBeanProperty[] creatorProps;
if (_valueInstantiator.canCreateFromObjectWith()) {
creatorProps = _valueInstantiator.getFromObjectArguments(ctxt.getConfig());
// 21-Jun-2015, tatu: This resolution was duplicated
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> later on and seems like
// it really should be only done at a later point. So commented out in 2.8.
// However, just in case there was a reason for it, leaving commented out
// here instead of immediately removing.
/*
// also: need to try to resolve 'external' type ids...
for (SettableBeanProperty prop : creatorProps) {
if (prop.hasValueTypeDeserializer()) {
TypeDeserializer typeDeser = prop.getValueTypeDeserializer();
if (typeDeser.getTypeInclusion() == JsonTypeInfo.As.EXTERNAL_PROPERTY) {
if (extTypes == null) {
extTypes = new ExternalTypeHandler.Builder();
}
extTypes.addExternal(prop, typeDeser);
}
}
}
*/
} else {
creatorProps = null;
}
UnwrappedPropertyHandler unwrapped = null;
for (SettableBeanProperty origProp : _beanProperties) {
SettableBeanProperty prop = origProp;
// May already have deserializer from annotations, if so, skip:
if (!prop.hasValueDeserializer()) {
// [databind#125]: allow use of converters
JsonDeserializer<?> deser = findConvertingDeserializer(ctxt, prop);
if (deser == null) {
deser = findDeserializer(ctxt, prop.getType(), prop);
}
prop = prop.withValueDeserializer(deser);
} else { // may need contextual version
JsonDeserializer<Object> deser = prop.getValueDeserializer();
/* Important! This is the only place where actually handle "primary"
* property deserializers -- call is different from other places.
*/
JsonDeserializer<?> cd = ctxt.handlePrimaryContextualization(deser, prop,
prop.getType());
if (cd != deser) {
prop = prop.withValueDeserializer(cd);
}
}
// Need to link managed references with matching back references
prop = _resolveManagedReferenceProperty(ctxt, prop);
// [databind#351[: need to wrap properties that require object id resolution.
if (!(prop instanceof ManagedReferenceProperty)) {
prop = _resolvedObjectIdProperty(ctxt, prop);
}
// Support unwrapped values (via @JsonUnwrapped)
SettableBeanProperty u = _resolveUnwrappedProperty(ctxt, prop);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> if (u != null) {
prop = u;
if (unwrapped == null) {
unwrapped = new UnwrappedPropertyHandler();
}
unwrapped.addProperty(prop);
/* 12-Dec-2014, tatu: As per [databind#647], we will have problems if
* the original property is left in place. So let's remove it now.
*/
_beanProperties.remove(prop);
continue;
}
// non-static inner classes too:
prop = _resolveInnerClassValuedProperty(ctxt, prop);
if (prop != origProp) {
_beanProperties.replace(prop);
// [databind#795]: Make sure PropertyBasedCreator's properties stay in sync
if (creatorProps != null) {
// 18-May-2015, tatu: _Should_ start with consistent set. But can we really
// fully count on this? May need to revisit in future; seems to hold for now.
for (int i = 0, len = creatorProps.length; i < len; ++i) {
if (creatorProps[i] == origProp) {
creatorProps[i] = prop;
break;
}
// ... as per above, it is possible we'd need to add this as fallback
// if (but only if) identity check fails?
/*
if (creatorProps[i].getName().equals(prop.getName())) {
creatorProps[i] = prop;
break;
}
*/
}
}
}
// one more thing: if this property uses "external property" type inclusion,
// it needs different handling altogether
if (prop.hasValueTypeDeserializer()) {
TypeDeserializer typeDeser = prop.getValueTypeDeserializer();
if (typeDeser.getTypeInclusion() == JsonTypeInfo.As.EXTERNAL_PROPERTY) {
if (extTypes == null) {
extTypes = new ExternalTypeHandler.Builder();
}
extTypes.addExternal(prop, typeDeser);
// In fact, remove from list of known properties to simplify later handling
_beanProperties.remove(prop);
continue;
}
}
}
// "any setter" may also need to be resolved now
if (_anySetter != null && !_anySetter
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Info);
}
JsonDeserializer<?> deser = ctxt.findRootValueDeserializer(idType);
oir = ObjectIdReader.construct(idType, objectIdInfo.getPropertyName(),
idGen, deser, idProp, resolver);
}
}
// either way, need to resolve serializer:
BeanDeserializerBase contextual = this;
if (oir != null && oir != _objectIdReader) {
contextual = contextual.withObjectIdReader(oir);
}
// And possibly add more properties to ignore
if (accessor != null) {
JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(accessor);
if (ignorals != null) {
Set<String> ignored = ignorals.findIgnoredForDeserialization();
if (!ignored.isEmpty()) {
Set<String> prev = contextual._ignorableProps;
if ((prev != null) && !prev.isEmpty()) {
ignored = new HashSet<String>(ignored);
ignored.addAll(prev);
}
contextual = contextual.withIgnorableProperties(ignored);
}
}
}
// One more thing: are we asked to serialize POJO as array?
JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType());
JsonFormat.Shape shape = null;
if (format != null) {
if (format.hasShape()) {
shape = format.getShape();
}
// 16-May-2016, tatu: How about per-property case-insensitivity?
Boolean B = format.getFeature(JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
if (B != null) {
// !!! TODO
BeanPropertyMap propsOrig = _beanProperties;
BeanPropertyMap props = propsOrig.withCaseInsensitivity(B.booleanValue());
if (props != propsOrig) {
contextual = contextual.withBeanProperties(props);
}
}
}
if (shape == null) {
shape = _serializationShape;
}
if (shape == JsonFormat.Shape.ARRAY) {
contextual = contextual.asArrayDeserializer();
}
return contextual;
}
/**
* Helper method called to see if given property is part of 'managed' property
* pair (managed
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>();
}
/**
* Overridden to return true for those instances that are
* handling value for which Object Identity handling is enabled
* (either via value type or referring property).
*/
@Override
public ObjectIdReader getObjectIdReader() {
return _objectIdReader;
}
public boolean hasProperty(String propertyName) {
return _beanProperties.find(propertyName) != null;
}
public boolean hasViews() {
return _needViewProcesing;
}
/**
* Accessor for checking number of deserialized properties.
*/
public int getPropertyCount() {
return _beanProperties.size();
}
@Override
public Collection<Object> getKnownPropertyNames() {
ArrayList<Object> names = new ArrayList<Object>();
for (SettableBeanProperty prop : _beanProperties) {
names.add(prop.getName());
}
return names;
}
/**
* @deprecated Since 2.3, use {@link #handledType()} instead
*/
@Deprecated
public final Class<?> getBeanClass() { return _beanType.getRawClass(); }
@Override
public JavaType getValueType() { return _beanType; }
/**
* Accessor for iterating over properties this deserializer uses; with
* the exception that properties passed via Creator methods
* (specifically, "property-based constructor") are not included,
* but can be accessed separate by calling
* {@link #creatorProperties}
*/
public Iterator<SettableBeanProperty> properties()
{
if (_beanProperties == null) {
throw new IllegalStateException("Can only call after BeanDeserializer has been resolved");
}
return _beanProperties.iterator();
}
/**
* Accessor for finding properties that represents values to pass
* through property-based creator method (constructor or
* factory method)
*
* @since 2.0
*/
public Iterator<SettableBeanProperty> creatorProperties()
{
if (_propertyBasedCreator == null) {
return Collections.<SettableBeanProperty>emptyList().iterator();
}
return _propertyBasedCreator.properties().iterator();
}
public SettableBeanProperty findProperty(PropertyName propertyName)
{
// TODO: start matching full name?
return findProperty(propertyName.getSimpleName());
}
/**
* Accessor for finding the property with given name, if
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> POJO
* has one. Name used is the external name, i.e. name used
* in external data representation (JSON).
*
* @since 2.0
*/
public SettableBeanProperty findProperty(String propertyName)
{
SettableBeanProperty prop = (_beanProperties == null) ?
null : _beanProperties.find(propertyName);
if (prop == null && _propertyBasedCreator != null) {
prop = _propertyBasedCreator.findCreatorProperty(propertyName);
}
return prop;
}
/**
* Alternate find method that tries to locate a property with given
* <code>property index</code>.
* Note that access by index is not necessarily faster than by name,
* since properties are not directly indexable; however, for most
* instances difference is not significant as number of properties
* is low.
*
* @since 2.3
*/
public SettableBeanProperty findProperty(int propertyIndex)
{
SettableBeanProperty prop = (_beanProperties == null) ?
null : _beanProperties.find(propertyIndex);
if (prop == null && _propertyBasedCreator != null) {
prop = _propertyBasedCreator.findCreatorProperty(propertyIndex);
}
return prop;
}
/**
* Method needed by {@link BeanDeserializerFactory} to properly link
* managed- and back-reference pairs.
*/
@Override
public SettableBeanProperty findBackReference(String logicalName)
{
if (_backRefs == null) {
return null;
}
return _backRefs.get(logicalName);
}
public ValueInstantiator getValueInstantiator() {
return _valueInstantiator;
}
/*
/**********************************************************
/* Mutators
/**********************************************************
*/
/**
* Method that can be used to replace an existing property with
* a modified one.
*<p>
* NOTE: only ever use this method if you know what you are doing;
* incorrect usage can break deserializer.
*
* @param original Property to replace
* @param replacement Property to replace it with
*
* @since 2.1
*/
public void replaceProperty(SettableBeanProperty original,
SettableBeanProperty replacement)
{
_beanProperties.replace(replacement);
}
/*
/
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Tokens != null) {
bean = handleUnknownProperties(ctxt, bean, unknownTokens);
}
// and/or things left to process via main parser?
if (p != null) {
bean = deserialize(p, ctxt, bean);
}
return bean;
}
/**
* Helper method called to (try to) locate deserializer for given sub-type of
* type that this deserializer handles.
*/
protected JsonDeserializer<Object> _findSubclassDeserializer(DeserializationContext ctxt,
Object bean, TokenBuffer unknownTokens)
throws IOException
{
JsonDeserializer<Object> subDeser;
// First: maybe we have already created sub-type deserializer?
synchronized (this) {
subDeser = (_subDeserializers == null) ? null : _subDeserializers.get(new ClassKey(bean.getClass()));
}
if (subDeser != null) {
return subDeser;
}
// If not, maybe we can locate one. First, need provider
JavaType type = ctxt.constructType(bean.getClass());
/* 30-Jan-2012, tatu: Ideally we would be passing referring
* property; which in theory we could keep track of via
* ResolvableDeserializer (if we absolutely must...).
* But for now, let's not bother.
*/
// subDeser = ctxt.findValueDeserializer(type, _property);
subDeser = ctxt.findRootValueDeserializer(type);
// Also, need to cache it
if (subDeser != null) {
synchronized (this) {
if (_subDeserializers == null) {
_subDeserializers = new HashMap<ClassKey,JsonDeserializer<Object>>();;
}
_subDeserializers.put(new ClassKey(bean.getClass()), subDeser);
}
}
return subDeser;
}
/*
/**********************************************************
/* Helper methods for error reporting
/**********************************************************
*/
/**
* Method that will modify caught exception (passed in as argument)
* as necessary to include reference information, and to ensure it
* is a subtype of {@link IOException}, or an unchecked exception.
*<p>
* Rules for wrapping and unwrapping are bit complicated; essentially:
*<ul>
* <li>Errors
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>with port number)
int i = value.lastIndexOf(']');
if (i == -1) {
throw new InvalidFormatException(ctxt.getParser(),
"Bracketed IPv6 address must contain closing bracket",
value, InetSocketAddress.class);
}
int j = value.indexOf(':', i);
int port = j > -1 ? Integer.parseInt(value.substring(j + 1)) : 0;
return new InetSocketAddress(value.substring(0, i + 1), port);
} else {
int ix = value.indexOf(':');
if (ix >= 0 && value.indexOf(':', ix + 1) < 0) {
// host:port
int port = Integer.parseInt(value.substring(ix+1));
return new InetSocketAddress(value.substring(0, ix), port);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> deserializerForCreator(DeserializationConfig config,
Class<?> enumClass, AnnotatedMethod factory,
ValueInstantiator valueInstantiator, SettableBeanProperty[] creatorProps)
{
if (config.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(factory.getMember(),
config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
}
return new FactoryBasedEnumDeserializer(enumClass, factory,
factory.getParameterType(0),
valueInstantiator, creatorProps);
}
/**
* Factory method used when Enum instances are to be deserialized
* using a zero-/no-args factory method
*
* @return Deserializer based on given no-args factory method
*
* @since 2.8
*/
public static JsonDeserializer<?> deserializerForNoArgsCreator(DeserializationConfig config,
Class<?> enumClass, AnnotatedMethod factory)
{
if (config.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(factory.getMember(),
config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
}
return new FactoryBasedEnumDeserializer(enumClass, factory);
}
/*
/**********************************************************
/* Default JsonDeserializer implementation
/**********************************************************
*/
/**
* Because of costs associated with constructing Enum resolvers,
* let's cache instances by default.
*/
@Override
public boolean isCachable() { return true; }
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken curr = p.getCurrentToken();
// Usually should just get string value:
if (curr == JsonToken.VALUE_STRING || curr == JsonToken.FIELD_NAME) {
CompactStringObjectMap lookup = ctxt.isEnabled(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
? _getToStringLookup(ctxt) : _lookupByName;
final String name = p.getText();
Object result = lookup.find(name);
if (result == null) {
return _deserializeAltString(p, ctxt, lookup, name);
}
return result;
}
// But let's consider int acceptable as well (if within ordinal range)
if (curr == JsonToken.VALUE_NUMBER_INT) {
// ... unless told not to do that
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> maximum) and close enough all in all:
if (_map.size() >= _maxEntries) {
synchronized (this) {
if (_map.size() >= _maxEntries) {
clear();
}
}
}
return _map.putIfAbsent(key, value);
}
// NOTE: key is of type Object only to retain binary backwards-compatibility
public V get(Object key) { return _map.get(key); }
public void clear() { _map.clear(); }
public int size() { return _map.size(); }
/*
/**********************************************************
/* Serializable overrides
/**********************************************************
*/
/**
* Ugly hack, to work through the requirement that _value is indeed final,
* and that JDK serialization won't call ctor(s) if Serializable is implemented.
*
* @since 2.1
*/
protected transient int _jdkSerializeMaxEntries;
private void readObject(ObjectInputStream in) throws IOException {
_jdkSerializeMaxEntries = in.readInt();
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeInt(_jdkSerializeMaxEntries);
}
protected Object readResolve() {
return new LRUMap<Object,Object>(_jdkSerializeMaxEntries, _jdkSerializeMaxEntries);
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> (suffix == null && _propertyIds != null) {
StringBuilder sb = new StringBuilder(100);
int len = _propertyIds.size();
if (len == 1) {
sb.append(" (one known property: \"");
sb.append(String.valueOf(_propertyIds.iterator().next()));
sb.append('"');
} else {
sb.append(" (").append(len).append(" known properties: ");
Iterator<Object> it = _propertyIds.iterator();
while (it.hasNext()) {
sb.append('"');
sb.append(String.valueOf(it.next()));
sb.append('"');
// one other thing: limit max length
if (sb.length() > MAX_DESC_LENGTH) {
sb.append(" [truncated]");
break;
}
if (it.hasNext()) {
sb.append(", ");
}
}
}
sb.append("])");
_propertiesAsString = suffix = sb.toString();
}
return suffix;
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Method for accessing type (class) that is missing definition to allow
* binding of the unrecognized property.
*/
public Class<?> getReferringClass() {
return _referringClass;
}
/**
* Convenience method for accessing logical property name that could
* not be mapped. Note that it is the last path reference in the
* underlying path.
*/
public String getPropertyName() {
return _propertyName;
}
public Collection<Object> getKnownPropertyIds()
{
if (_propertyIds == null) {
return null;
}
return Collections.unmodifiableCollection(_propertyIds);
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>link ObjectMapper#copy} will work
* properly; specifically, that caches are cleared, but settings
* will otherwise remain identical; and that no sharing of state
* occurs.
*
* @since 2.4.4
*/
public DefaultDeserializationContext copy() {
throw new IllegalStateException("DefaultDeserializationContext sub-class not overriding copy()");
}
/*
/**********************************************************
/* Abstract methods impls, Object Id
/**********************************************************
*/
@Override
public ReadableObjectId findObjectId(Object id, ObjectIdGenerator<?> gen, ObjectIdResolver resolverType)
{
/* 02-Apr-2015, tatu: As per [databind#742] should allow 'null', similar to how
* missing id already works.
*/
if (id == null) {
return null;
}
final ObjectIdGenerator.IdKey key = gen.key(id);
if (_objectIds == null) {
_objectIds = new LinkedHashMap<ObjectIdGenerator.IdKey,ReadableObjectId>();
} else {
ReadableObjectId entry = _objectIds.get(key);
if (entry != null) {
return entry;
}
}
// Not seen yet, must create entry and configure resolver.
ObjectIdResolver resolver = null;
if (_objectIdResolvers == null) {
_objectIdResolvers = new ArrayList<ObjectIdResolver>(8);
} else {
for (ObjectIdResolver res : _objectIdResolvers) {
if (res.canUseFor(resolverType)) {
resolver = res;
break;
}
}
}
if (resolver == null) {
resolver = resolverType.newForDeserialization(this);
_objectIdResolvers.add(resolver);
}
ReadableObjectId entry = createReadableObjectId(key);
entry.setResolver(resolver);
_objectIds.put(key, entry);
return entry;
}
/**
* Overridable factory method to create a new instance of ReadableObjectId or its
* subclass. It is meant to be overridden when custom ReadableObjectId is
* needed for {@link #tryToResolveUnresolvedObjectId}.
* Default implementation simply constructs default {@link ReadableObjectId} with
* given <code>key</code>.
*
* @param key The key to associate with the new ReadableObjectId
* @return New ReadableObjectId instance
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.util.List;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
/**
* This intermediate base class is used for all leaf nodes, that is,
* all non-container (array or object) nodes, except for the
* "missing node".
*/
public abstract class ValueNode
extends BaseJsonNode
{
protected ValueNode() { }
@Override
protected JsonNode _at(JsonPointer ptr) {
// will only allow direct matches, but no traversal through
// (base class checks for direct match)
return MissingNode.getInstance();
}
/**
* All current value nodes are immutable, so we can just return
* them as is.
*/
@SuppressWarnings("unchecked")
@Override
public <T extends JsonNode> T deepCopy() { return (T) this; }
@Override public abstract JsonToken asToken();
@Override
public void serializeWithType(JsonGenerator jg, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonProcessingException
{
typeSer.writeTypePrefixForScalar(this, jg);
serialize(jg, provider);
typeSer.writeTypeSuffixForScalar(this, jg);
}
/*
/**********************************************************************
/* Base impls for standard methods
/**********************************************************************
*/
@Override
public String toString() { return asText(); }
/*
**********************************************************************
* Navigation methods
**********************************************************************
*/
@Override
public final JsonNode get(int index) { return null; }
@Override
public final JsonNode path(int index) { return MissingNode.getInstance(); }
@Override
public final boolean has(int index) { return false; }
@Override
public final boolean hasNonNull(int index) { return false; }
@Override
public final JsonNode get(String fieldName) { return null; }
@Override
public final JsonNode path(String fieldName) { return MissingNode.getInstance(); }
@Override
public final boolean has(String fieldName) { return false; }
@Override
public final boolean hasNonNull(String fieldName) { return false
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>atedMember getMember();
@Override
public abstract <A extends Annotation> A getAnnotation(Class<A> acls);
@Override
public <A extends Annotation> A getContextAnnotation(Class<A> acls) {
return _contextAnnotations.get(acls);
}
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider)
throws JsonMappingException
{
if (isRequired()) {
objectVisitor.property(this);
} else {
objectVisitor.optionalProperty(this);
}
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
protected final Class<?> getDeclaringClass() {
return getMember().getDeclaringClass();
}
public String getManagedReferenceName() { return _managedReferenceName; }
public ObjectIdInfo getObjectIdInfo() { return _objectIdInfo; }
public boolean hasValueDeserializer() {
return (_valueDeserializer != null) && (_valueDeserializer != MISSING_VALUE_DESERIALIZER);
}
public boolean hasValueTypeDeserializer() { return (_valueTypeDeserializer != null); }
public JsonDeserializer<Object> getValueDeserializer() {
JsonDeserializer<Object> deser = _valueDeserializer;
if (deser == MISSING_VALUE_DESERIALIZER) {
return null;
}
return deser;
}
public TypeDeserializer getValueTypeDeserializer() { return _valueTypeDeserializer; }
public boolean visibleInView(Class<?> activeView) {
return (_viewMatcher == null) || _viewMatcher.isVisibleForView(activeView);
}
public boolean hasViews() { return _viewMatcher != null; }
/**
* Method for accessing unique index of this property; indexes are
* assigned once all properties of a {@link BeanDeserializer} have
* been collected.
*
* @return Index of this property
*/
public int getPropertyIndex() { return _propertyIndex; }
/**
* Method for accessing index of the creator property: for other
* types of properties will simply return -1.
*
* @since 2.1
*/
public int getCreatorIndex() { return -1; }
/**
* Accessor for id of injectable value, if this bean property supports
* value injection.
*/
public Object getInjectableValueId() { return null; }
/*
/**********************************************************
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>getMetadata(cls).getDeclaredAnnotations();
}
/**
* @since 2.7
*/
public static Ctor[] getConstructors(Class<?> cls) {
return _getMetadata(cls).getConstructors();
}
// // // Then methods that do NOT cache access but were considered
// // // (and could be added to do caching if it was proven effective)
/**
* @since 2.7
*/
public static Class<?> getDeclaringClass(Class<?> cls) {
// Caching does not seem worthwhile, as per profiling
return isObjectOrPrimitive(cls) ? null : cls.getDeclaringClass();
}
/**
* @since 2.7
*/
public static Type getGenericSuperclass(Class<?> cls) {
return cls.getGenericSuperclass();
}
/**
* @since 2.7
*/
public static Type[] getGenericInterfaces(Class<?> cls) {
return _getMetadata(cls).getGenericInterfaces();
}
/**
* @since 2.7
*/
public static Class<?> getEnclosingClass(Class<?> cls) {
// Caching does not seem worthwhile, as per profiling
return isObjectOrPrimitive(cls) ? null : cls.getEnclosingClass();
}
private static Class<?>[] _interfaces(Class<?> cls) {
return _getMetadata(cls).getInterfaces();
}
private static ClassMetadata _getMetadata(Class<?> cls)
{
ClassMetadata md = sCached.get(cls);
if (md == null) {
md = new ClassMetadata(cls);
// tiny optimization, but in case someone concurrently constructed it,
// let's use that instance, to reduce extra concurrent work.
ClassMetadata old = sCached.putIfAbsent(cls, md);
if (old != null) {
md = old;
}
}
return md;
}
/*
/**********************************************************
/* Method type detection methods
/**********************************************************
*/
/**
* @deprecated Since 2.6 not used; may be removed before 3.x
*/
@Deprecated // since 2.6
public static boolean hasGetterSignature(Method m)
{
// First: static methods can't be getters
if (Modifier.isStatic(m.getModifiers())) {
return false;
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> following fields to store information about actual Enumeration
// type for EnumSets, EnumMaps...
enumSetTypeField = locateField(EnumSet.class, "elementType", Class.class);
enumMapTypeField = locateField(EnumMap.class, "elementType", Class.class);
}
@SuppressWarnings("unchecked")
public Class<? extends Enum<?>> enumTypeFor(EnumSet<?> set)
{
if (enumSetTypeField != null) {
return (Class<? extends Enum<?>>) get(set, enumSetTypeField);
}
throw new IllegalStateException("Can not figure out type for EnumSet (odd JDK platform?)");
}
@SuppressWarnings("unchecked")
public Class<? extends Enum<?>> enumTypeFor(EnumMap<?,?> set)
{
if (enumMapTypeField != null) {
return (Class<? extends Enum<?>>) get(set, enumMapTypeField);
}
throw new IllegalStateException("Can not figure out type for EnumMap (odd JDK platform?)");
}
private Object get(Object bean, Field field)
{
try {
return field.get(bean);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
private static Field locateField(Class<?> fromClass, String expectedName, Class<?> type)
{
Field found = null;
// First: let's see if we can find exact match:
Field[] fields = getDeclaredFields(fromClass);
for (Field f : fields) {
if (expectedName.equals(f.getName()) && f.getType() == type) {
found = f;
break;
}
}
// And if not, if there is just one field with the type, that field
if (found == null) {
for (Field f : fields) {
if (f.getType() == type) {
// If more than one, can't choose
if (found != null) return null;
found = f;
}
}
}
if (found != null) { // it's non-public, need to force accessible
try {
found.setAccessible(true
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
if (result == null) {
result = isObjectOrPrimitive() ? NO_ANNOTATIONS : _forClass.getDeclaredAnnotations();
_annotations = result;
}
return result;
}
// 19-Sep-2015, tatu: Some performance improvement, after finding this
// in profile; maybe 8-10% in "wasteful" deserialization case
public Ctor[] getConstructors() {
Ctor[] result = _constructors;
if (result == null) {
// Note: can NOT skip abstract classes as they may be used with mix-ins
// and for regular use shouldn't really matter.
if (_forClass.isInterface() || isObjectOrPrimitive()) {
result = NO_CTORS;
} else {
Constructor<?>[] rawCtors = _forClass.getDeclaredConstructors();
final int len = rawCtors.length;
result = new Ctor[len];
for (int i = 0; i < len; ++i) {
result[i] = new Ctor(rawCtors[i]);
}
}
_constructors = result;
}
return result;
}
// 21-Spe-2015, tatu: Surprisingly significant improvement (+10%)...
public Field[] getDeclaredFields() {
Field[] fields = _fields;
if (fields == null) {
fields = _forClass.getDeclaredFields();
_fields = fields;
}
return fields;
}
// 21-Spe-2015, tatu: Surprisingly significant improvement (+30%)...
public Method[] getDeclaredMethods() {
Method[] methods = _methods;
if (methods == null) {
methods = _forClass.getDeclaredMethods();
_methods = methods;
}
return methods;
}
// Prominently listed on profiling when not cached, improvement
// modest, 1-2% range; but at least is measurable so keep it
public boolean hasEnclosingMethod() {
Boolean b = _hasEnclosingMethod;
if (b == null) {
b = isObjectOrPrimitive() ? Boolean.FALSE : Boolean.valueOf(_forClass.getEnclosingMethod() != null);
_hasEnclosingMethod
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.util.Collections;
import com.fasterxml.jackson.databind.util.ClassUtil;
/**
* Intermediate base class for annotated entities that are members of
* a class; fields, methods and constructors. This is a superset
* of things that can represent logical properties as it contains
* constructors in addition to fields and methods.
*/
public abstract class AnnotatedMember
extends Annotated
implements java.io.Serializable
{
private static final long serialVersionUID = 1L; // since 2.5
// 19-Dec-2014, tatu: Similarly, assumed NOT to be needed in cases where
// owning object (ObjectMapper or relatives) is being JDK-serialized
/**
* Context object needed for resolving generic type associated with this
* member (method parameter or return value, or field type).
*
* @since 2.7
*/
protected final transient TypeResolutionContext _typeContext;
// Transient since information not needed after construction, so
// no need to persist
protected final transient AnnotationMap _annotations;
protected AnnotatedMember(TypeResolutionContext ctxt, AnnotationMap annotations) {
super();
_typeContext = ctxt;
_annotations = annotations;
}
/**
* Copy-constructor.
*
* @since 2.5
*/
protected AnnotatedMember(AnnotatedMember base) {
_typeContext = base._typeContext;
_annotations = base._annotations;
}
/**
* Actual physical class in which this memmber was declared.
*/
public abstract Class<?> getDeclaringClass();
public abstract Member getMember();
/**
* Accessor for {@link TypeResolutionContext} that is used for resolving
* full generic type of this member.
*
* @since 2.7
*/
public TypeResolutionContext getTypeContext() {
return _typeContext;
}
@Override
public final <A extends Annotation> A getAnnotation(Class<A> acls) {
if (_annotations == null) {
return null;
}
return _annotations.get(acls);
}
@Override
public final boolean hasAnnotation(Class<?> acls)
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.jsontype.impl;
import java.util.*;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
/**
* Standard {@link SubtypeResolver} implementation.
*/
public class StdSubtypeResolver
extends SubtypeResolver
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected LinkedHashSet<NamedType> _registeredSubtypes;
public StdSubtypeResolver() { }
/*
/**********************************************************
/* Subtype registration
/**********************************************************
*/
@Override
public void registerSubtypes(NamedType... types) {
if (_registeredSubtypes == null) {
_registeredSubtypes = new LinkedHashSet<NamedType>();
}
for (NamedType type : types) {
_registeredSubtypes.add(type);
}
}
@Override
public void registerSubtypes(Class<?>... classes) {
NamedType[] types = new NamedType[classes.length];
for (int i = 0, len = classes.length; i < len; ++i) {
types[i] = new NamedType(classes[i]);
}
registerSubtypes(types);
}
/*
/**********************************************************
/* Resolution by class (serialization)
/**********************************************************
*/
@Override
public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config,
AnnotatedMember property, JavaType baseType)
{
final AnnotationIntrospector ai = config.getAnnotationIntrospector();
// for backwards compatibility, must allow null here:
Class<?> rawBase = (baseType == null) ? property.getRawType() : baseType.getRawClass();
HashMap<NamedType, NamedType> collected = new HashMap<NamedType, NamedType>();
// start with registered subtypes (which have precedence)
if (_registeredSubtypes != null) {
for (NamedType subtype : _registeredSubtypes) {
// is it a subtype of root type
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> rawBase = type.getRawType();
for (NamedType subtype : _registeredSubtypes) {
// is it a subtype of root type?
if (rawBase.isAssignableFrom(subtype.getType())) { // yes
AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config);
_collectAndResolveByTypeId(curr, subtype, config, typesHandled, byName);
}
}
}
return _combineNamedAndUnnamed(typesHandled, byName);
}
/*
/**********************************************************
/* Deprecated method overrides
/**********************************************************
*/
@Override
@Deprecated
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedMember property,
MapperConfig<?> config, AnnotationIntrospector ai, JavaType baseType)
{
return collectAndResolveSubtypesByClass(config, property, baseType);
}
@Override
@Deprecated
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass type,
MapperConfig<?> config, AnnotationIntrospector ai)
{
return collectAndResolveSubtypesByClass(config, type);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
/**
* Method called to find subtypes for a specific type (class), using
* type (class) as the unique key (in case of conflicts).
*/
protected void _collectAndResolve(AnnotatedClass annotatedType, NamedType namedType,
MapperConfig<?> config, AnnotationIntrospector ai,
HashMap<NamedType, NamedType> collectedSubtypes)
{
if (!namedType.hasName()) {
String name = ai.findTypeName(annotatedType);
if (name != null) {
namedType = new NamedType(namedType.getType(), name);
}
}
// First things first: is base type itself included?
if (collectedSubtypes.containsKey(namedType)) {
// if so, no recursion; however, may need to update name?
if (namedType.hasName()) {
NamedType prev = collectedSubtypes.get(namedType);
if (!prev.hasName()) {
collectedSubtypes.put(namedType, namedType);
}
}
return;
}
// if it wasn't, add and check subtypes recursively
collectedSubtypes.put(namedType, namedType);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> false;
FiveMinuteUser other = (FiveMinuteUser) o;
if (_isVerified != other._isVerified) return false;
if (_gender != other._gender) return false;
if (!_name.equals(other._name)) return false;
byte[] otherImage = other._userImage;
if (otherImage.length != _userImage.length) return false;
for (int i = 0, len = _userImage.length; i < len; ++i) {
if (_userImage[i] != otherImage[i]) {
return false;
}
}
return true;
}
}
/*
/**********************************************************
/* High-level helpers
/**********************************************************
*/
protected void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents)
throws IOException
{
verifyJsonSpecSampleDoc(jp, verifyContents, true);
}
protected void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents,
boolean requireNumbers)
throws IOException
{
if (!jp.hasCurrentToken()) {
jp.nextToken();
}
assertToken(JsonToken.START_OBJECT, jp.getCurrentToken()); // main object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Image'
if (verifyContents) {
verifyFieldName(jp, "Image");
}
assertToken(JsonToken.START_OBJECT, jp.nextToken()); // 'image' object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Width'
if (verifyContents) {
verifyFieldName(jp, "Width");
}
verifyIntToken(jp.nextToken(), requireNumbers);
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_WIDTH);
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Height'
if (verifyContents) {
verifyFieldName(jp, "Height");
}
verifyIntToken(jp.nextToken(), requireNumbers);
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_HEIGHT);
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Title'
if (verifyContents) {
verifyFieldName(jp, "Title");
}
assertToken(JsonToken.VALUE_STRING
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> */
protected String getAndVerifyText(JsonParser jp)
throws IOException, JsonParseException
{
// Ok, let's verify other accessors
int actLen = jp.getTextLength();
char[] ch = jp.getTextCharacters();
String str2 = new String(ch, jp.getTextOffset(), actLen);
String str = jp.getText();
if (str.length() != actLen) {
fail("Internal problem (jp.token == "+jp.getCurrentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen);
}
assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);
return str;
}
/*
/**********************************************************
/* And other helpers
/**********************************************************
*/
protected byte[] encodeInUTF32BE(String input)
{
int len = input.length();
byte[] result = new byte[len * 4];
int ptr = 0;
for (int i = 0; i < len; ++i, ptr += 4) {
char c = input.charAt(i);
result[ptr] = result[ptr+1] = (byte) 0;
result[ptr+2] = (byte) (c >> 8);
result[ptr+3] = (byte) c;
}
return result;
}
public String quote(String str) {
return '"'+str+'"';
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import com.fasterxml.jackson.databind.*;
/**
* Container class that contains serializers for JDK types that
* require special handling for some reason.
*/
public class JdkDeserializers
{
private final static HashSet<String> _classNames = new HashSet<String>();
static {
// note: can skip primitive types; other ways to check them:
Class<?>[] types = new Class<?>[] {
UUID.class,
AtomicBoolean.class,
StackTraceElement.class,
ByteBuffer.class
};
for (Class<?> cls : types) { _classNames.add(cls.getName()); }
for (Class<?> cls : FromStringDeserializer.types()) { _classNames.add(cls.getName()); }
}
public static JsonDeserializer<?> find(Class<?> rawType, String clsName)
{
if (_classNames.contains(clsName)) {
JsonDeserializer<?> d = FromStringDeserializer.findDeserializer(rawType);
if (d != null) {
return d;
}
if (rawType == UUID.class) {
return new UUIDDeserializer();
}
if (rawType == StackTraceElement.class) {
return new StackTraceElementDeserializer();
}
if (rawType == AtomicBoolean.class) {
// (note: AtomicInteger/Long work due to single-arg constructor. For now?
return new AtomicBooleanDeserializer();
}
if (rawType == ByteBuffer.class) {
return new ByteBufferDeserializer();
}
}
return null;
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> IOException
{
JsonDeserializer<Object> deser = _deserializers.get(typeId);
if (deser == null) {
/* As per [Databind#305], need to provide contextual info. But for
* backwards compatibility, let's start by only supporting this
* for base class, not via interface. Later on we can add this
* to the interface, assuming deprecation at base class helps.
*/
JavaType type = _idResolver.typeFromId(ctxt, typeId);
if (type == null) {
// As per [JACKSON-614], use the default impl if no type id available:
deser = _findDefaultImplDeserializer(ctxt);
if (deser == null) {
// 10-May-2016, tatu: We may get some help...
JavaType actual = _handleUnknownTypeId(ctxt, typeId, _idResolver, _baseType);
if (actual == null) { // what should this be taken to mean?
// TODO: try to figure out something better
return null;
}
// ... would this actually work?
deser = ctxt.findContextualValueDeserializer(actual, _property);
}
} else {
/* 16-Dec-2010, tatu: Since nominal type we get here has no (generic) type parameters,
* we actually now need to explicitly narrow from base type (which may have parameterization)
* using raw type.
*
* One complication, though; can not change 'type class' (simple type to container); otherwise
* we may try to narrow a SimpleType (Object.class) into MapType (Map.class), losing actual
* type in process (getting SimpleType of Map.class which will not work as expected)
*/
if ((_baseType != null)
&& _baseType.getClass() == type.getClass()) {
/* 09-Aug-2015, tatu: Not sure if the second part of the check makes sense;
* but it appears to check that JavaType impl class is the same which is
* important for some reason?
* Disabling the check will break 2 Enum-related tests.
*/
// 19-Jun-201
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>> _result;
/**
* A list of {@link MapReferring} to maintain ordering.
*/
private List<MapReferring> _accumulator = new ArrayList<MapReferring>();
public MapReferringAccumulator(Class<?> valueType, Map<Object, Object> result) {
_valueType = valueType;
_result = result;
}
public void put(Object key, Object value)
{
if (_accumulator.isEmpty()) {
_result.put(key, value);
} else {
MapReferring ref = _accumulator.get(_accumulator.size() - 1);
ref.next.put(key, value);
}
}
public Referring handleUnresolvedReference(UnresolvedForwardReference reference, Object key)
{
MapReferring id = new MapReferring(this, reference, _valueType, key);
_accumulator.add(id);
return id;
}
public void resolveForwardReference(Object id, Object value) throws IOException
{
Iterator<MapReferring> iterator = _accumulator.iterator();
// Resolve ordering after resolution of an id. This means either:
// 1- adding to the result map in case of the first unresolved id.
// 2- merge the content of the resolved id with its previous unresolved id.
Map<Object,Object> previous = _result;
while (iterator.hasNext()) {
MapReferring ref = iterator.next();
if (ref.hasId(id)) {
iterator.remove();
previous.put(ref.key, value);
previous.putAll(ref.next);
return;
}
previous = ref.next;
}
throw new IllegalArgumentException("Trying to resolve a forward reference with id [" + id
+ "] that wasn't previously seen as unresolved.");
}
}
/**
* Helper class to maintain processing order of value.
* The resolved object associated with {@link #key} comes before the values in
* {@link #next}.
*/
static class MapReferring extends Referring {
private final MapReferringAccumulator _parent;
public final Map<Object, Object> next = new LinkedHashMap<Object, Object>();
public final Object key;
MapReferring(MapReferringAccumulator parent, UnresolvedForwardReference ref,
Class<?> valueType, Object key)
{
super
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.std.StaticListSerializerBase;
/**
* Efficient implement for serializing {@link List}s that contains Strings and are random-accessible.
* The only complexity is due to possibility that serializer for {@link String}
* may be overridde; because of this, logic is needed to ensure that the default
* serializer is in use to use fastest mode, or if not, to defer to custom
* String serializer.
*/
@JacksonStdImpl
public final class IndexedStringListSerializer
extends StaticListSerializerBase<List<String>>
{
private static final long serialVersionUID = 1L;
public final static IndexedStringListSerializer instance = new IndexedStringListSerializer();
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected IndexedStringListSerializer() {
super(List.class);
}
public IndexedStringListSerializer(IndexedStringListSerializer src,
JsonSerializer<?> ser, Boolean unwrapSingle) {
super(src, ser, unwrapSingle);
}
@Override
public JsonSerializer<?> _withResolved(BeanProperty prop,
JsonSerializer<?> ser, Boolean unwrapSingle) {
return new IndexedStringListSerializer(this, ser, unwrapSingle);
}
@Override protected JsonNode contentSchema() { return createSchemaNode("string", true); }
@Override
protected void acceptContentVisitor(JsonArrayFormatVisitor visitor) throws JsonMappingException {
visitor.itemsFormat(JsonFormatTypes.STRING);
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public void serialize(List<String> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrap
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Single == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
_serializeUnwrapped(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
if (_serializer == null) {
serializeContents(value, gen, provider, len);
} else {
serializeUsingCustom(value, gen, provider, len);
}
gen.writeEndArray();
}
private final void _serializeUnwrapped(List<String> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
if (_serializer == null) {
serializeContents(value, gen, provider, 1);
} else {
serializeUsingCustom(value, gen, provider, 1);
}
}
@Override
public void serializeWithType(List<String> value, JsonGenerator gen,
SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
final int len = value.size();
typeSer.writeTypePrefixForArray(value, gen);
if (_serializer == null) {
serializeContents(value, gen, provider, len);
} else {
serializeUsingCustom(value, gen, provider, len);
}
typeSer.writeTypeSuffixForArray(value, gen);
}
private final void serializeContents(List<String> value, JsonGenerator gen,
SerializerProvider provider, int len) throws IOException
{
int i = 0;
try {
for (; i < len; ++i) {
String str = value.get(i);
if (str == null) {
provider.defaultSerializeNull(gen);
} else {
gen.writeString(str);
}
}
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
private final void serializeUsingCustom(List<String> value, JsonGenerator gen,
SerializerProvider provider, int len) throws IOException
{
int i = 0;
try {
final JsonSerializer<String> ser = _serializer;
for (i = 0; i < len; ++i) {
String str = value.get(i);
if (str == null) {
provider.defaultSerializeNull(gen);
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> else {
ser.serialize(str, gen, provider);
}
}
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.std.StaticListSerializerBase;
/**
* Efficient implement for serializing {@link Collection}s that contain Strings.
* The only complexity is due to possibility that serializer for {@link String}
* may be overridde; because of this, logic is needed to ensure that the default
* serializer is in use to use fastest mode, or if not, to defer to custom
* String serializer.
*/
@JacksonStdImpl
@SuppressWarnings("serial")
public class StringCollectionSerializer
extends StaticListSerializerBase<Collection<String>>
{
public final static StringCollectionSerializer instance = new StringCollectionSerializer();
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected StringCollectionSerializer() {
super(Collection.class);
}
protected StringCollectionSerializer(StringCollectionSerializer src,
JsonSerializer<?> ser, Boolean unwrapSingle)
{
super(src, ser, unwrapSingle);
}
@Override
public JsonSerializer<?> _withResolved(BeanProperty prop,
JsonSerializer<?> ser, Boolean unwrapSingle) {
return new StringCollectionSerializer(this, ser, unwrapSingle);
}
@Override protected JsonNode contentSchema() {
return createSchemaNode("string", true);
}
@Override
protected void acceptContentVisitor(JsonArrayFormatVisitor visitor) throws JsonMappingException
{
visitor.itemsFormat(JsonFormatTypes.STRING);
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public void serialize(Collection<String> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
_serializeUnwrapped(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
if (_serializer == null) {
serializeContents(value, gen, provider);
} else {
serializeUsingCustom(value, gen, provider);
}
gen.writeEndArray();
}
private final void _serializeUnwrapped(Collection<String> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
if (_serializer == null) {
serializeContents(value, gen, provider);
} else {
serializeUsingCustom(value, gen, provider);
}
}
@Override
public void serializeWithType(Collection<String> value, JsonGenerator jgen, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonGenerationException
{
typeSer.writeTypePrefixForArray(value, jgen);
if (_serializer == null) {
serializeContents(value, jgen, provider);
} else {
serializeUsingCustom(value, jgen, provider);
}
typeSer.writeTypeSuffixForArray(value, jgen);
}
private final void serializeContents(Collection<String> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonGenerationException
{
if (_serializer != null) {
serializeUsingCustom(value, jgen, provider);
return;
}
int i = 0;
for (String str : value) {
try {
if (str == null) {
provider.defaultSerializeNull(jgen);
} else {
jgen.writeString(str);
}
++i;
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
}
private void serializeUsingCustom(Collection<String> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonGenerationException
{
final JsonSerializer<String> ser = _serializer;
int i = 0;
for (String str : value) {
try {
if (str == null) {
provider.defaultSerializeNull(jgen);
} else {
ser.serialize(str, jgen, provider);
}
} catch (Exception e
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>) {
wrapAndThrow(provider, e, value, i);
}
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>SuppressWarnings("unchecked")
public <T> T getValueHandler() { return (T) _valueHandler; }
@Override
@SuppressWarnings("unchecked")
public <T> T getTypeHandler() { return (T) _typeHandler; }
@Override
public TypeBindings getBindings() {
return _bindings;
}
@Override
public int containedTypeCount() {
return _bindings.size();
}
@Override
public JavaType containedType(int index) {
return _bindings.getBoundType(index);
}
@Override
@Deprecated
public String containedTypeName(int index) {
return _bindings.getBoundName(index);
}
@Override
public JavaType getSuperClass() {
return _superClass;
}
@Override
public List<JavaType> getInterfaces() {
if (_superInterfaces == null) {
return Collections.emptyList();
}
switch (_superInterfaces.length) {
case 0:
return Collections.emptyList();
case 1:
return Collections.singletonList(_superInterfaces[0]);
}
return Arrays.asList(_superInterfaces);
}
@Override
public final JavaType findSuperType(Class<?> rawTarget)
{
if (rawTarget == _class) {
return this;
}
// Check super interfaces first:
if (rawTarget.isInterface() && (_superInterfaces != null)) {
for (int i = 0, count = _superInterfaces.length; i < count; ++i) {
JavaType type = _superInterfaces[i].findSuperType(rawTarget);
if (type != null) {
return type;
}
}
}
// and if not found, super class and its supertypes
if (_superClass != null) {
JavaType type = _superClass.findSuperType(rawTarget);
if (type != null) {
return type;
}
}
return null;
}
@Override
public JavaType[] findTypeParameters(Class<?> expType)
{
JavaType match = findSuperType(expType);
if (match == null) {
return NO_TYPES;
}
return match.getBindings().typeParameterArray();
}
/*
/**********************************************************
/* JsonSerializable base implementation
/**********************************************************
*/
@Override
public
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> void serializeWithType(JsonGenerator gen, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonProcessingException
{
typeSer.writeTypePrefixForScalar(this, gen);
this.serialize(gen, provider);
typeSer.writeTypeSuffixForScalar(this, gen);
}
@Override
public void serialize(JsonGenerator gen, SerializerProvider provider)
throws IOException, JsonProcessingException
{
gen.writeString(toCanonical());
}
/*
/**********************************************************
/* Methods for sub-classes to use
/**********************************************************
*/
/**
* @param trailingSemicolon Whether to add trailing semicolon for non-primitive
* (reference) types or not
*/
protected static StringBuilder _classSignature(Class<?> cls, StringBuilder sb,
boolean trailingSemicolon)
{
if (cls.isPrimitive()) {
if (cls == Boolean.TYPE) {
sb.append('Z');
} else if (cls == Byte.TYPE) {
sb.append('B');
}
else if (cls == Short.TYPE) {
sb.append('S');
}
else if (cls == Character.TYPE) {
sb.append('C');
}
else if (cls == Integer.TYPE) {
sb.append('I');
}
else if (cls == Long.TYPE) {
sb.append('J');
}
else if (cls == Float.TYPE) {
sb.append('F');
}
else if (cls == Double.TYPE) {
sb.append('D');
}
else if (cls == Void.TYPE) {
sb.append('V');
} else {
throw new IllegalStateException("Unrecognized primitive type: "+cls.getName());
}
} else {
sb.append('L');
String name = cls.getName();
for (int i = 0, len = name.length(); i < len; ++i) {
char c = name.charAt(i);
if (c == '.') c = '/';
sb.append(c);
}
if (trailingSemicolon) {
sb.append(';');
}
}
return sb;
}
/**
* Internal helper method used to figure out nominal super-class for
* deprecated factory methods / constructors, where we are not given
* properly
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.impl.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.util.NameTransformer;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Class that handles deserialization using a separate
* Builder class, which is used for data binding and
* produces actual deserialized value at the end
* of data binding.
*<p>
* Note on implementation: much of code has been copied from
* {@link BeanDeserializer}; there may be opportunities to
* refactor this in future.
*/
public class BuilderBasedDeserializer
extends BeanDeserializerBase
{
private static final long serialVersionUID = 1L;
protected final AnnotatedMethod _buildMethod;
/*
/**********************************************************
/* Life-cycle, construction, initialization
/**********************************************************
*/
/**
* Constructor used by {@link BeanDeserializerBuilder}.
*/
public BuilderBasedDeserializer(BeanDeserializerBuilder builder,
BeanDescription beanDesc,
BeanPropertyMap properties, Map<String, SettableBeanProperty> backRefs,
Set<String> ignorableProps, boolean ignoreAllUnknown,
boolean hasViews)
{
super(builder, beanDesc, properties, backRefs,
ignorableProps, ignoreAllUnknown, hasViews);
_buildMethod = builder.getBuildMethod();
// 05-Mar-2012, tatu: Can not really make Object Ids work with builders, not yet anyway
if (_objectIdReader != null) {
throw new IllegalArgumentException("Can not use Object Id with Builder-based deserialization (type "
+beanDesc.getType()+")");
}
}
/**
* Copy-constructor that can be used by sub-classes to allow
* copy-on-write styling copying of settings of an existing instance.
*/
protected BuilderBasedDeserializer(BuilderBasedDeserializer src)
{
this(src, src._ignoreAllUnknown);
}
protected BuilderBasedDeserializer(BuilderBasedDeserializer src, boolean ignoreAllUnknown)
{
super(src, ignoreAllUnknown);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> _buildMethod = src._buildMethod;
}
protected BuilderBasedDeserializer(BuilderBasedDeserializer src, NameTransformer unwrapper) {
super(src, unwrapper);
_buildMethod = src._buildMethod;
}
public BuilderBasedDeserializer(BuilderBasedDeserializer src, ObjectIdReader oir) {
super(src, oir);
_buildMethod = src._buildMethod;
}
public BuilderBasedDeserializer(BuilderBasedDeserializer src, Set<String> ignorableProps) {
super(src, ignorableProps);
_buildMethod = src._buildMethod;
}
public BuilderBasedDeserializer(BuilderBasedDeserializer src, BeanPropertyMap props) {
super(src, props);
_buildMethod = src._buildMethod;
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* main thing really is to just enforce ignoring of unknown
* properties; since there may be multiple unwrapped values
* and properties for all may be interleaved...
*/
return new BuilderBasedDeserializer(this, unwrapper);
}
@Override
public BeanDeserializerBase withObjectIdReader(ObjectIdReader oir) {
return new BuilderBasedDeserializer(this, oir);
}
@Override
public BeanDeserializerBase withIgnorableProperties(Set<String> ignorableProps) {
return new BuilderBasedDeserializer(this, ignorableProps);
}
@Override
public BeanDeserializerBase withBeanProperties(BeanPropertyMap props) {
return new BuilderBasedDeserializer(this, props);
}
@Override
protected BeanDeserializerBase asArrayDeserializer() {
SettableBeanProperty[] props = _beanProperties.getPropertiesInInsertionOrder();
return new BeanAsArrayBuilderDeserializer(this, props, _buildMethod);
}
/*
/**********************************************************
/* JsonDeserializer implementation
/**********************************************************
*/
protected final Object finishBuild(DeserializationContext ctxt, Object builder)
throws IOException
{
// As per [databind#777], allow returning builder itself
if (null == _buildMethod) {
return builder;
}
try {
return _buildMethod.getMember().invoke(builder);
} catch (Exception e) {
return wrapInstantiationProblem(e, ctxt);
}
}
/**
* Main deserialization method for bean-based objects (POJOs).
*/
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
}
if (_unwrappedPropertyHandler != null) {
return deserializeWithUnwrapped(p, ctxt, builder);
}
if (_externalTypeIdHandler != null) {
return deserializeWithExternalTypeId(p, ctxt, builder);
}
if (_needViewProcesing) {
Class<?> view = ctxt.getActiveView();
if (view != null) {
return deserializeWithView(p, ctxt, builder, view);
}
}
JsonToken t = p.getCurrentToken();
// 23-Mar-2010, tatu: In some cases, we start with full JSON object too...
if (t == JsonToken.START_OBJECT) {
t = p.nextToken();
}
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
// Skip field name:
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
builder = prop.deserializeSetAndReturn(p, ctxt, builder);
} catch (Exception e) {
wrapAndThrow(e, builder, propName, ctxt);
}
continue;
}
handleUnknownVanilla(p, ctxt, handledType(), propName);
}
return builder;
}
/**
* Streamlined version that is only used when no "special"
* features are enabled.
*/
private final Object vanillaDeserialize(JsonParser p,
DeserializationContext ctxt, JsonToken t)
throws IOException, JsonProcessingException
{
Object bean = _valueInstantiator.createUsingDefault(ctxt);
for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
String propName = p.getCurrentName();
// Skip field name:
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
bean = prop.deserializeSetAndReturn(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
} else {
handleUnknownVanilla(p, ctxt, bean, propName);
}
}
return bean;
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> /**
* General version used when handling needs more advanced
* features.
*/
@Override
public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (_nonStandardCreation) {
if (_unwrappedPropertyHandler != null) {
return deserializeWithUnwrapped(p, ctxt);
}
if (_externalTypeIdHandler != null) {
return deserializeWithExternalTypeId(p, ctxt);
}
return deserializeFromObjectUsingNonDefault(p, ctxt);
}
Object bean = _valueInstantiator.createUsingDefault(ctxt);
if (_injectables != null) {
injectValues(ctxt, bean);
}
if (_needViewProcesing) {
Class<?> view = ctxt.getActiveView();
if (view != null) {
return deserializeWithView(p, ctxt, bean, view);
}
}
for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
String propName = p.getCurrentName();
// Skip field name:
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
bean = prop.deserializeSetAndReturn(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
handleUnknownVanilla(p, ctxt, bean, propName);
}
return bean;
}
/**
* Method called to deserialize bean using "property-based creator":
* this means that a non-default constructor or factory method is
* called, and then possibly other setters. The trick is that
* values for creator method need to be buffered, first; and
* due to non-guaranteed ordering possibly some other properties
* as well.
*/
@Override
@SuppressWarnings("resource")
protected final Object _deserializeUsingPropertyBased(final JsonParser p,
final DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
// 04-Jan-2010, tatu: May need to collect unknown properties for
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> polymorphic cases
TokenBuffer unknown = null;
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue; // never gets here
}
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
return handlePolymorphic(p, ctxt, bean, unknown);
}
if (unknown != null) { // nope, just extra unknown stuff...
bean = handleUnknownProperties(ctxt, bean, unknown);
}
// or just clean?
return _deserialize(p, ctxt, bean);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, prop.deserialize(p, ctxt));
continue;
}
// As per [JACKSON-313], things marked as ignorable should not be
// passed to any setter
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, handledType(), propName);
continue;
}
// "any property"?
if (_anySetter != null) {
buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(p, ctxt));
continue;
}
// Ok then, let's collect the whole field; name and value
if (unknown == null) {
unknown = new TokenBuffer(p, ctxt);
}
unknown
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>.writeFieldName(propName);
unknown.copyCurrentStructure(p);
}
// We hit END_OBJECT, so:
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
bean = wrapInstantiationProblem(e, ctxt);
}
if (unknown != null) {
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
return handlePolymorphic(null, ctxt, bean, unknown);
}
// no, just some extra unknown properties
return handleUnknownProperties(ctxt, bean, unknown);
}
return bean;
}
/*
/**********************************************************
/* Deserializing when we have to consider an active View
/**********************************************************
*/
protected final Object deserializeWithView(JsonParser p, DeserializationContext ctxt,
Object bean, Class<?> activeView)
throws IOException, JsonProcessingException
{
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
// Skip field name:
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
if (!prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
bean = prop.deserializeSetAndReturn(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
handleUnknownVanilla(p, ctxt, bean, propName);
}
return bean;
}
/*
/**********************************************************
/* Handling for cases where we have "unwrapped" values
/**********************************************************
*/
/**
* Method called when there are declared "unwrapped" properties
* which need special handling
*/
@SuppressWarnings("resource")
protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (_delegateDeserializer != null) {
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt));
}
if (_propertyBasedCreator != null) {
return deserializeUsingPropertyBasedWithUnwrapped(p, ctxt);
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
Object bean = _valueInstantiator.createUsingDefault(ctxt);
if (_injectables != null) {
injectValues(ctxt, bean);
}
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
bean = prop.deserializeSetAndReturn(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// ignorable things should be ignored
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// how about any setter? We'll get copies but...
if (_anySetter != null) {
try {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
}
tokens.writeEndObject();
_unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
return bean;
}
@SuppressWarnings("resource")
protected Object deserializeWithUnwrapped(JsonParser p,
DeserializationContext ctxt, Object bean)
throws IOException, JsonProcessingException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.START_OBJECT) {
t = p.nextToken();
}
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() :
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> null;
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
SettableBeanProperty prop = _beanProperties.find(propName);
p.nextToken();
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
bean = prop.deserializeSetAndReturn(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// how about any setter? We'll get copies but...
if (_anySetter != null) {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
}
}
tokens.writeEndObject();
_unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
return bean;
}
@SuppressWarnings("resource")
protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p,
DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue; // never gets here
}
// if so, need to copy all remaining tokens into buffer
while (t == JsonToken.FIELD_NAME) {
p.nextToken(); // to skip name
tokens.copyCurrentStructure(p);
t = p.nextToken();
}
tokens.writeEndObject();
if (bean.getClass() != _beanType.getRawClass()) {
// !!! 08-Jul-2011, tatu: Could probably support; but for now
// it's too complicated, so bail out
ctxt.reportMappingException("Can not create polymorphic instances with unwrapped values");
return null;
}
return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, prop.deserialize(p, ctxt));
continue;
}
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, handledType(), propName);
continue;
}
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// "any property"?
if (_anySetter != null) {
buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(p, ctxt));
}
}
// We hit END_OBJECT, so:
Object bean;
// !!! 15-Feb-2012, tatu: Need to modify creator to use Builder!
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
return wrapInstantiationProblem(e, ctxt);
}
return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
}
/*
/**********************************************************
/* Handling for cases where we have property/-ies with
/* external type id
/**********************************************************
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> */
protected Object deserializeWithExternalTypeId(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (_propertyBasedCreator != null) {
return deserializeUsingPropertyBasedWithExternalTypeId(p, ctxt);
}
return deserializeWithExternalTypeId(p, ctxt, _valueInstantiator.createUsingDefault(ctxt));
}
protected Object deserializeWithExternalTypeId(JsonParser p,
DeserializationContext ctxt, Object bean)
throws IOException, JsonProcessingException
{
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
final ExternalTypeHandler ext = _externalTypeIdHandler.start();
for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
bean = prop.deserializeSetAndReturn(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// ignorable things should be ignored
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but others are likely to be part of external type id thingy...
if (ext.handlePropertyValue(p, ctxt, propName, bean)) {
continue;
}
// if not, the usual fallback handling:
if (_anySetter != null) {
try {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
} else {
// Unknown: let's call handler method
handleUnknownProperty(p, ctxt, bean, propName);
}
}
// and when we get this far, let's try finalizing the deal:
return ext.complete(p, ctxt, bean);
}
protected Object deserializeUsingPropertyBasedWithExternalTypeId
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> }
// Also: this is a superset of "forClassAnnotations", so may optimize by optional add:
_cachedFCA.putIfAbsent(type, desc);
}
return desc;
}
@Override
public BasicBeanDescription forDeserializationWithBuilder(DeserializationConfig cfg,
JavaType type, MixInResolver r)
{
// no std JDK types with Builders, so:
BasicBeanDescription desc = BasicBeanDescription.forDeserialization(collectPropertiesWithBuilder(cfg,
type, r, false));
// this is still a superset of "forClassAnnotations", so may optimize by optional add:
_cachedFCA.putIfAbsent(type, desc);
return desc;
}
@Override
public BasicBeanDescription forCreation(DeserializationConfig cfg,
JavaType type, MixInResolver r)
{
BasicBeanDescription desc = _findStdTypeDesc(type);
if (desc == null) {
// As per [Databind#550], skip full introspection for some of standard
// structured types as well
desc = _findStdJdkCollectionDesc(cfg, type);
if (desc == null) {
desc = BasicBeanDescription.forDeserialization(
collectProperties(cfg, type, r, false, "set"));
}
}
// should this be cached for FCA?
return desc;
}
@Override
public BasicBeanDescription forClassAnnotations(MapperConfig<?> config,
JavaType type, MixInResolver r)
{
BasicBeanDescription desc = _findStdTypeDesc(type);
if (desc == null) {
desc = _cachedFCA.get(type);
if (desc == null) {
AnnotatedClass ac = AnnotatedClass.construct(type, config, r);
desc = BasicBeanDescription.forOtherUse(config, type, ac);
_cachedFCA.put(type, desc);
}
}
return desc;
}
@Override
public BasicBeanDescription forDirectClassAnnotations(MapperConfig<?> config,
JavaType type, MixInResolver r)
{
BasicBeanDescription desc = _findStdTypeDesc(type);
if (desc == null) {
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(type.getRawClass(), config, r);
desc = BasicBeanDescription
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>.class);
_acceptInt = (cls == Integer.TYPE) || cls.isAssignableFrom(Integer.class);
_acceptDouble = (cls == Double.TYPE) || cls.isAssignableFrom(Double.class);
}
/**
* Factory method used when constructing instances for non-POJO types, like
* {@link java.util.Map}s.
*
* @since 2.3
*/
public static AbstractDeserializer constructForNonPOJO(BeanDescription beanDesc) {
return new AbstractDeserializer(beanDesc);
}
/*
/**********************************************************
/* Public accessors
/**********************************************************
*/
@Override
public Class<?> handledType() {
return _baseType.getRawClass();
}
@Override
public boolean isCachable() { return true; }
/**
* Overridden to return true for those instances that are
* handling value for which Object Identity handling is enabled
* (either via value type or referring property).
*/
@Override
public ObjectIdReader getObjectIdReader() {
return _objectIdReader;
}
/**
* Method called by <code>BeanDeserializer</code> to resolve back reference
* part of managed references.
*/
@Override
public SettableBeanProperty findBackReference(String logicalName) {
return (_backRefProperties == null) ? null : _backRefProperties.get(logicalName);
}
/*
/**********************************************************
/* Deserializer implementation
/**********************************************************
*/
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException
{
// Hmmh. One tricky question; for scalar, is it an Object Id, or "Natural" type?
// for now, prefer Object Id:
if (_objectIdReader != null) {
JsonToken t = p.getCurrentToken();
if (t != null) {
// Most commonly, a scalar (int id, uuid String, ...)
if (t.isScalarValue()) {
return _deserializeFromObjectId(p, ctxt);
}
// but, with 2.5+, a simple Object-wrapped value also legal:
if (t == JsonToken.START_OBJECT) {
t = p.nextToken();
}
if ((t == JsonToken.FIELD_NAME) && _objectIdReader.maySerializeAsObject()
&& _
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>JsonParser p, DeserializationContext ctxt, int paramCount,
ObjectIdReader oir)
{
_parser = p;
_context = ctxt;
_paramsNeeded = paramCount;
_objectIdReader = oir;
_creatorParameters = new Object[paramCount];
if (paramCount < 32) {
_paramsSeenBig = null;
} else {
_paramsSeenBig = new BitSet();
}
}
/**
* Returns {@code true} if the given property was seen in the JSON source by
* this buffer.
*
* @since 2.8
*/
public final boolean hasParameter(SettableBeanProperty prop)
{
if (_paramsSeenBig == null) {
return ((_paramsSeen >> prop.getCreatorIndex()) & 1) == 1;
} else {
return _paramsSeenBig.get(prop.getCreatorIndex());
}
}
/**
* A variation of {@link #getParameters(SettableBeanProperty[])} that
* accepts a single property. Whereas the plural form eagerly fetches and
* validates all properties, this method may be used (along with
* {@link #hasParameter(SettableBeanProperty)}) to let applications only
* fetch the properties defined in the JSON source itself, and to have some
* other customized behavior for missing properties.
*
* @since 2.8
*/
public Object getParameter(SettableBeanProperty prop)
throws JsonMappingException
{
Object value;
if (hasParameter(prop)) {
value = _creatorParameters[prop.getCreatorIndex()];
} else {
value = _creatorParameters[prop.getCreatorIndex()] = _findMissing(prop);
}
if (value == null && _context.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)) {
throw _context.mappingException(
"Null value for creator property '%s'; DeserializationFeature.FAIL_ON_NULL_FOR_CREATOR_PARAMETERS enabled",
prop.getName(), prop.getCreatorIndex());
}
return value;
}
/**
* Method called to do necessary post-processing such as injection of values
* and verification of values for required properties,
* after either {@link #assignParameter(SettableBeanProperty, Object)}
* returns <code
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>>true</code> (to indicate all creator properties are found), or when
* then whole JSON Object has been processed,
*/
public Object[] getParameters(SettableBeanProperty[] props)
throws JsonMappingException
{
// quick check to see if anything else is needed
if (_paramsNeeded > 0) {
if (_paramsSeenBig == null) {
int mask = _paramsSeen;
// not optimal, could use `Integer.trailingZeroes()`, but for now should not
// really matter for common cases
for (int ix = 0, len = _creatorParameters.length; ix < len; ++ix, mask >>= 1) {
if ((mask & 1) == 0) {
_creatorParameters[ix] = _findMissing(props[ix]);
}
}
} else {
final int len = _creatorParameters.length;
for (int ix = 0; (ix = _paramsSeenBig.nextClearBit(ix)) < len; ++ix) {
_creatorParameters[ix] = _findMissing(props[ix]);
}
}
}
if (_context.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)) {
for (int ix = 0; ix < props.length; ++ix) {
if (_creatorParameters[ix] == null) {
_context.reportMappingException("Null value for creator property '%s'; DeserializationFeature.FAIL_ON_NULL_FOR_CREATOR_PARAMETERS enabled",
props[ix].getName(), props[ix].getCreatorIndex());
}
}
}
return _creatorParameters;
}
protected Object _findMissing(SettableBeanProperty prop) throws JsonMappingException
{
// First: do we have injectable value?
Object injectableValueId = prop.getInjectableValueId();
if (injectableValueId != null) {
return _context.findInjectableValue(prop.getInjectableValueId(),
prop, null);
}
// Second: required?
if (prop.isRequired()) {
_context.reportMappingException("Missing required creator property '%s' (index %d)",
prop.getName(), prop.getCreatorIndex());
}
if (_context.isEnabled(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES)) {
_
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> int newValue = (old | (1 << ix));
if (old != newValue) {
_paramsSeen = newValue;
if (--_paramsNeeded <= 0) {
return true;
}
}
} else {
if (!_paramsSeenBig.get(ix)) {
if (--_paramsNeeded <= 0) {
return true;
}
_paramsSeenBig.set(ix);
}
}
return false;
}
public void bufferProperty(SettableBeanProperty prop, Object value) {
_buffered = new PropertyValue.Regular(_buffered, value, prop);
}
public void bufferAnyProperty(SettableAnyProperty prop, String propName, Object value) {
_buffered = new PropertyValue.Any(_buffered, value, prop, propName);
}
public void bufferMapProperty(Object key, Object value) {
_buffered = new PropertyValue.Map(_buffered, value, key);
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Type withTypeHandler(Object h) {
if (_typeHandler == h) {
return this;
}
return new SimpleType(_class, _bindings, _superClass, _superInterfaces, _valueHandler, h, _asStatic);
}
@Override
public JavaType withContentTypeHandler(Object h) {
// no content type, so:
throw new IllegalArgumentException("Simple types have no content types; can not call withContenTypeHandler()");
}
@Override
public SimpleType withValueHandler(Object h) {
if (h == _valueHandler) {
return this;
}
return new SimpleType(_class, _bindings, _superClass, _superInterfaces, h, _typeHandler, _asStatic);
}
@Override
public SimpleType withContentValueHandler(Object h) {
// no content type, so:
throw new IllegalArgumentException("Simple types have no content types; can not call withContenValueHandler()");
}
@Override
public SimpleType withStaticTyping() {
return _asStatic ? this : new SimpleType(_class, _bindings,
_superClass, _superInterfaces, _valueHandler, _typeHandler, true);
}
@Override
public JavaType refine(Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces) {
// SimpleType means something not-specialized, so:
return null;
}
@Override
protected String buildCanonicalName()
{
StringBuilder sb = new StringBuilder();
sb.append(_class.getName());
final int count = _bindings.size();
if (count > 0) {
sb.append('<');
for (int i = 0; i < count; ++i) {
JavaType t = containedType(i);
if (i > 0) {
sb.append(',');
}
sb.append(t.toCanonical());
}
sb.append('>');
}
return sb.toString();
}
/*
/**********************************************************
/* Public API
/**********************************************************
*/
@Override
public boolean isContainerType() { return false; }
@Override
public boolean hasContentType() { return false; }
@Override
public StringBuilder getErasedSignature(StringBuilder sb) {
return _classSignature(_class, sb, true);
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
@Override
public StringBuilder getGenericSignature(StringBuilder sb)
{
_classSignature(_class, sb, false);
final int count = _bindings.size();
if (count > 0) {
sb.append('<');
for (int i = 0; i < count; ++i) {
sb = containedType(i).getGenericSignature(sb);
}
sb.append('>');
}
sb.append(';');
return sb;
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
/**
* Helper method we need to recursively build skeletal representations
* of superclasses.
*
* @since 2.7 -- remove when not needed (2.8?)
*/
private static JavaType _buildSuperClass(Class<?> superClass, TypeBindings b)
{
if (superClass == null) {
return null;
}
if (superClass == Object.class) {
return TypeFactory.unknownType();
}
JavaType superSuper = _buildSuperClass(superClass.getSuperclass(), b);
return new SimpleType(superClass, b,
superSuper, null, null, null, false);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(40);
sb.append("[simple type, class ").append(buildCanonicalName()).append(']');
return sb.toString();
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
SimpleType other = (SimpleType) o;
// Classes must be identical...
if (other._class != this._class) return false;
// And finally, generic bindings, if any
TypeBindings b1 = _bindings;
TypeBindings b2 = other._bindings;
return b1.equals(b2);
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>> getInjectables() {
if (!_collected) {
collectAll();
}
return _injectables;
}
public AnnotatedMethod getJsonValueMethod()
{
if (!_collected) {
collectAll();
}
// If @JsonValue defined, must have a single one
if (_jsonValueGetters != null) {
if (_jsonValueGetters.size() > 1) {
reportProblem("Multiple value properties defined ("+_jsonValueGetters.get(0)+" vs "
+_jsonValueGetters.get(1)+")");
}
// otherwise we won't greatly care
return _jsonValueGetters.get(0);
}
return null;
}
public AnnotatedMember getAnyGetter()
{
if (!_collected) {
collectAll();
}
if (_anyGetters != null) {
if (_anyGetters.size() > 1) {
reportProblem("Multiple 'any-getters' defined ("+_anyGetters.get(0)+" vs "
+_anyGetters.get(1)+")");
}
return _anyGetters.getFirst();
}
return null;
}
public AnnotatedMember getAnySetterField()
{
if (!_collected) {
collectAll();
}
if (_anySetterField != null) {
if (_anySetterField.size() > 1) {
reportProblem("Multiple 'any-Setters' defined ("+_anySetters.get(0)+" vs "
+_anySetterField.get(1)+")");
}
return _anySetterField.getFirst();
}
return null;
}
public AnnotatedMethod getAnySetterMethod()
{
if (!_collected) {
collectAll();
}
if (_anySetters != null) {
if (_anySetters.size() > 1) {
reportProblem("Multiple 'any-setters' defined ("+_anySetters.get(0)+" vs "
+_anySetters.get(1)+")");
}
return _anySetters.getFirst();
}
return null;
}
/**
* Accessor for set of properties that are explicitly marked to be ignored
* via per-property markers (but NOT class annotations).
*/
public Set<String> getIgnoredPropertyNames
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>).addField(f, pn, nameExplicit, visible, ignored);
}
}
/**
* Method for collecting basic information on constructor(s) found
*/
protected void _addCreators(Map<String, POJOPropertyBuilder> props)
{
// can be null if annotation processing is disabled...
if (_annotationIntrospector == null) {
return;
}
for (AnnotatedConstructor ctor : _classDef.getConstructors()) {
if (_creatorProperties == null) {
_creatorProperties = new LinkedList<POJOPropertyBuilder>();
}
for (int i = 0, len = ctor.getParameterCount(); i < len; ++i) {
_addCreatorParam(props, ctor.getParameter(i));
}
}
for (AnnotatedMethod factory : _classDef.getStaticMethods()) {
if (_creatorProperties == null) {
_creatorProperties = new LinkedList<POJOPropertyBuilder>();
}
for (int i = 0, len = factory.getParameterCount(); i < len; ++i) {
_addCreatorParam(props, factory.getParameter(i));
}
}
}
/**
* @since 2.4
*/
protected void _addCreatorParam(Map<String, POJOPropertyBuilder> props,
AnnotatedParameter param)
{
// JDK 8, paranamer, Scala can give implicit name
String impl = _annotationIntrospector.findImplicitPropertyName(param);
if (impl == null) {
impl = "";
}
PropertyName pn = _annotationIntrospector.findNameForDeserialization(param);
boolean expl = (pn != null && !pn.isEmpty());
if (!expl) {
if (impl.isEmpty()) {
/* Important: if neither implicit nor explicit name, can not make use
* of this creator parameter -- may or may not be a problem, verified
* at a later point.
*/
return;
}
// Also: if this occurs, there MUST be explicit annotation on creator itself
if (!_annotationIntrospector.hasCreatorAnnotation(param.getOwner())) {
return;
}
pn = PropertyName.construct(impl);
}
// shouldn't need to worry about @JsonIgnore, since creators only added
// if so annotated
/* 13-May-2015,
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
prop.removeNonVisible(inferMutators);
}
}
/**
* Helper method called to add explicitly ignored properties to a list
* of known ignored properties; this helps in proper reporting of
* errors.
*/
private void _collectIgnorals(String name)
{
if (!_forSerialization) {
if (_ignoredPropertyNames == null) {
_ignoredPropertyNames = new HashSet<String>();
}
_ignoredPropertyNames.add(name);
}
}
/*
/**********************************************************
/* Internal methods; renaming properties
/**********************************************************
*/
protected void _renameProperties(Map<String, POJOPropertyBuilder> props)
{
// With renaming need to do in phases: first, find properties to rename
Iterator<Map.Entry<String,POJOPropertyBuilder>> it = props.entrySet().iterator();
LinkedList<POJOPropertyBuilder> renamed = null;
while (it.hasNext()) {
Map.Entry<String, POJOPropertyBuilder> entry = it.next();
POJOPropertyBuilder prop = entry.getValue();
Collection<PropertyName> l = prop.findExplicitNames();
// no explicit names? Implicit one is fine as is
if (l.isEmpty()) {
continue;
}
it.remove(); // need to replace with one or more renamed
if (renamed == null) {
renamed = new LinkedList<POJOPropertyBuilder>();
}
// simple renaming? Just do it
if (l.size() == 1) {
PropertyName n = l.iterator().next();
renamed.add(prop.withName(n));
continue;
}
// but this may be problematic...
renamed.addAll(prop.explode(l));
/*
String newName = prop.findNewName();
if (newName != null) {
if (renamed == null) {
renamed = new LinkedList<POJOPropertyBuilder>();
}
prop = prop.withSimpleName(newName);
renamed.add(prop);
it.remove();
}
*/
}
// and if any were renamed, merge back in...
if (renamed != null) {
for (POJOPropertyBuilder prop : renamed) {
String name = prop.getName();
POJOPropertyBuilder old = props.get(name);
if (old == null)
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>-687], need to consider case where there may already be
* something in there...
*/
POJOPropertyBuilder old = propMap.get(simpleName);
if (old == null) {
propMap.put(simpleName, prop);
} else {
old.addAll(prop);
}
// replace the creatorProperty too, if there is one
_updateCreatorProperty(prop, _creatorProperties);
}
}
protected void _renameWithWrappers(Map<String, POJOPropertyBuilder> props)
{
/* 11-Sep-2012, tatu: To support 'MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME',
* need another round of renaming...
*/
Iterator<Map.Entry<String,POJOPropertyBuilder>> it = props.entrySet().iterator();
LinkedList<POJOPropertyBuilder> renamed = null;
while (it.hasNext()) {
Map.Entry<String, POJOPropertyBuilder> entry = it.next();
POJOPropertyBuilder prop = entry.getValue();
AnnotatedMember member = prop.getPrimaryMember();
if (member == null) {
continue;
}
PropertyName wrapperName = _annotationIntrospector.findWrapperName(member);
// One trickier part (wrt [Issue#24] of JAXB annotations: wrapper that
// indicates use of actual property... But hopefully has been taken care
// of previously
if (wrapperName == null || !wrapperName.hasSimpleName()) {
continue;
}
if (!wrapperName.equals(prop.getFullName())) {
if (renamed == null) {
renamed = new LinkedList<POJOPropertyBuilder>();
}
prop = prop.withName(wrapperName);
renamed.add(prop);
it.remove();
}
}
// and if any were renamed, merge back in...
if (renamed != null) {
for (POJOPropertyBuilder prop : renamed) {
String name = prop.getName();
POJOPropertyBuilder old = props.get(name);
if (old == null) {
props.put(name, prop);
} else {
old.addAll(prop);
}
}
}
}
/*
/**********************************************************
/* Overridable internal methods, sorting, other stuff
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
/**********************************************************
*/
/* First, order by [JACKSON-90] (explicit ordering and/or alphabetic)
* and then for [JACKSON-170] (implicitly order creator properties before others)
*/
protected void _sortProperties(Map<String, POJOPropertyBuilder> props)
{
// Then how about explicit ordering?
AnnotationIntrospector intr = _annotationIntrospector;
boolean sort;
Boolean alpha = (intr == null) ? null : intr.findSerializationSortAlphabetically((Annotated) _classDef);
if (alpha == null) {
sort = _config.shouldSortPropertiesAlphabetically();
} else {
sort = alpha.booleanValue();
}
String[] propertyOrder = (intr == null) ? null : intr.findSerializationPropertyOrder(_classDef);
// no sorting? no need to shuffle, then
if (!sort && (_creatorProperties == null) && (propertyOrder == null)) {
return;
}
int size = props.size();
Map<String, POJOPropertyBuilder> all;
// Need to (re)sort alphabetically?
if (sort) {
all = new TreeMap<String,POJOPropertyBuilder>();
} else {
all = new LinkedHashMap<String,POJOPropertyBuilder>(size+size);
}
for (POJOPropertyBuilder prop : props.values()) {
all.put(prop.getName(), prop);
}
Map<String,POJOPropertyBuilder> ordered = new LinkedHashMap<String,POJOPropertyBuilder>(size+size);
// Ok: primarily by explicit order
if (propertyOrder != null) {
for (String name : propertyOrder) {
POJOPropertyBuilder w = all.get(name);
if (w == null) { // also, as per [JACKSON-268], we will allow use of "implicit" names
for (POJOPropertyBuilder prop : props.values()) {
if (name.equals(prop.getInternalName())) {
w = prop;
// plus re-map to external name, to avoid dups:
name = prop.getName();
break;
}
}
}
if (w != null) {
ordered.put(name, w);
}
}
}
// And secondly by sorting
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> Creator properties before other unordered properties
if (_creatorProperties != null) {
/* As per [databind#311], this is bit delicate; but if alphabetic ordering
* is mandated, at least ensure creator properties are in alphabetic
* order. Related question of creator vs non-creator is punted for now,
* so creator properties still fully predate non-creator ones.
*/
Collection<POJOPropertyBuilder> cr;
if (sort) {
TreeMap<String, POJOPropertyBuilder> sorted =
new TreeMap<String,POJOPropertyBuilder>();
for (POJOPropertyBuilder prop : _creatorProperties) {
sorted.put(prop.getName(), prop);
}
cr = sorted.values();
} else {
cr = _creatorProperties;
}
for (POJOPropertyBuilder prop : cr) {
ordered.put(prop.getName(), prop);
}
}
// And finally whatever is left (trying to put again will not change ordering)
ordered.putAll(all);
props.clear();
props.putAll(ordered);
}
/*
/**********************************************************
/* Internal methods; helpers
/**********************************************************
*/
protected void reportProblem(String msg) {
throw new IllegalArgumentException("Problem with definition of "+_classDef+": "+msg);
}
protected POJOPropertyBuilder _property(Map<String, POJOPropertyBuilder> props,
PropertyName name) {
return _property(props, name.getSimpleName());
}
// !!! TODO: deprecate, require use of PropertyName
protected POJOPropertyBuilder _property(Map<String, POJOPropertyBuilder> props,
String implName)
{
POJOPropertyBuilder prop = props.get(implName);
if (prop == null) {
prop = new POJOPropertyBuilder(_config, _annotationIntrospector, _forSerialization,
PropertyName.construct(implName));
props.put(implName, prop);
}
return prop;
}
private PropertyNamingStrategy _findNamingStrategy()
{
Object namingDef = (_annotationIntrospector == null)? null
: _annotationIntrospector.findNamingStrategy(_classDef);
if (namingDef == null) {
return _config.getPropertyNamingStrategy();
}
if (namingDef instanceof PropertyNamingStrategy
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>) {
return (PropertyNamingStrategy) namingDef;
}
/* Alas, there's no way to force return type of "either class
* X or Y" -- need to throw an exception after the fact
*/
if (!(namingDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned PropertyNamingStrategy definition of type "
+namingDef.getClass().getName()+"; expected type PropertyNamingStrategy or Class<PropertyNamingStrategy> instead");
}
Class<?> namingClass = (Class<?>)namingDef;
// 09-Nov-2015, tatu: Need to consider pseudo-value of STD, which means "use default"
if (namingClass == PropertyNamingStrategy.class) {
return null;
}
if (!PropertyNamingStrategy.class.isAssignableFrom(namingClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "
+namingClass.getName()+"; expected Class<PropertyNamingStrategy>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
if (hi != null) {
PropertyNamingStrategy pns = hi.namingStrategyInstance(_config, _classDef, namingClass);
if (pns != null) {
return pns;
}
}
return (PropertyNamingStrategy) ClassUtil.createInstance(namingClass,
_config.canOverrideAccessModifiers());
}
protected void _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
if (creatorProperties != null) {
for (int i = 0, len = creatorProperties.size(); i < len; ++i) {
if (creatorProperties.get(i).getInternalName().equals(prop.getInternalName())) {
creatorProperties.set(i, prop);
break;
}
}
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> be:
*<pre>
* TypeFactory.constructParametrizedType(ArrayList.class, List.class, Integer.class);
*</pre>
* since parameterization is applied to {@link java.util.List}.
* In most cases distinction does not matter, but there are types where it does;
* one such example is parameterization of types that implement {@link java.util.Iterator}.
*<p>
* NOTE: type modifiers are NOT called on constructed type.
*
* @param parametrized Actual full type
* @param parameterClasses Type parameters to apply
*
* @since 2.5 NOTE: was briefly deprecated for 2.6
*/
public JavaType constructParametricType(Class<?> parametrized, Class<?>... parameterClasses) {
int len = parameterClasses.length;
JavaType[] pt = new JavaType[len];
for (int i = 0; i < len; ++i) {
pt[i] = _fromClass(null, parameterClasses[i], null);
}
return constructParametricType(parametrized, pt);
}
/**
* Factory method for constructing {@link JavaType} that
* represents a parameterized type. For example, to represent
* type <code>List<Set<Integer>></code>, you could
* call
*<pre>
* JavaType inner = TypeFactory.constructParametrizedType(Set.class, Set.class, Integer.class);
* return TypeFactory.constructParametrizedType(ArrayList.class, List.class, inner);
*</pre>
*<p>
* The reason for first two arguments to be separate is that parameterization may
* apply to a super-type. For example, if generic type was instead to be
* constructed for <code>ArrayList<Integer></code>, the usual call would be:
*<pre>
* TypeFactory.constructParametrizedType(ArrayList.class, List.class, Integer.class);
*</pre>
* since parameterization is applied to {@link java.util.List}.
* In most cases distinction does not matter, but there are types where it does;
* one such example is parameterization of types that implement {@link java.util.Iterator}.
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>size()) {
case 0: // acceptable?
kt = vt = _unknownType();
break;
case 2:
kt = typeParams.get(0);
vt = typeParams.get(1);
break;
default:
throw new IllegalArgumentException("Strange Map type "+rawClass.getName()+": can not determine type parameters");
}
}
return MapType.construct(rawClass, bindings, superClass, superInterfaces, kt, vt);
}
private JavaType _collectionType(Class<?> rawClass, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces)
{
List<JavaType> typeParams = bindings.getTypeParameters();
// ok to have no types ("raw")
JavaType ct;
if (typeParams.isEmpty()) {
ct = _unknownType();
} else if (typeParams.size() == 1) {
ct = typeParams.get(0);
} else {
throw new IllegalArgumentException("Strange Collection type "+rawClass.getName()+": can not determine type parameters");
}
return CollectionType.construct(rawClass, bindings, superClass, superInterfaces, ct);
}
private JavaType _referenceType(Class<?> rawClass, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces)
{
List<JavaType> typeParams = bindings.getTypeParameters();
// ok to have no types ("raw")
JavaType ct;
if (typeParams.isEmpty()) {
ct = _unknownType();
} else if (typeParams.size() == 1) {
ct = typeParams.get(0);
} else {
throw new IllegalArgumentException("Strange Reference type "+rawClass.getName()+": can not determine type parameters");
}
return ReferenceType.construct(rawClass, bindings, superClass, superInterfaces, ct);
}
/**
* Factory method to call when no special {@link JavaType} is needed,
* no generic parameters are passed. Default implementation may check
* pre-constructed values for "well-known" types, but if none found
* will simply call {@link #_newSimpleType}
*
* @since 2.7
*/
protected JavaType _constructSimple(Class<?> raw, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces)
{
if (bindings
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> generic
* types) into actual types
*/
protected JavaType _fromClass(ClassStack context, Class<?> rawType, TypeBindings bindings)
{
// Very first thing: small set of core types we know well:
JavaType result = _findWellKnownSimple(rawType);
if (result != null) {
return result;
}
// Barring that, we may have recently constructed an instance:
// !!! TODO 16-Oct-2015, tatu: For now let's only cached non-parameterized; otherwise
// need better cache key
boolean cachable = (bindings == null) || bindings.isEmpty();
if (cachable) {
result = _typeCache.get(rawType); // ok, cache object is synced
if (result != null) {
return result;
}
}
// 15-Oct-2015, tatu: recursive reference?
if (context == null) {
context = new ClassStack(rawType);
} else {
ClassStack prev = context.find(rawType);
if (prev != null) {
// Self-reference: needs special handling, then...
ResolvedRecursiveType selfRef = new ResolvedRecursiveType(rawType, EMPTY_BINDINGS);
prev.addSelfReference(selfRef);
return selfRef;
}
// no, but need to update context to allow for proper cycle resolution
context = context.child(rawType);
}
// First: do we have an array type?
if (rawType.isArray()) {
result = ArrayType.construct(_fromAny(context, rawType.getComponentType(), bindings),
bindings);
} else {
// If not, need to proceed by first resolving parent type hierarchy
JavaType superClass;
JavaType[] superInterfaces;
if (rawType.isInterface()) {
superClass = null;
superInterfaces = _resolveSuperInterfaces(context, rawType, bindings);
} else {
// Note: even Enums can implement interfaces, so can not drop those
superClass = _resolveSuperClass(context, rawType, bindings);
superInterfaces = _resolveSuperInterfaces(context, rawType, bindings);
}
// 19-Oct-2015, tatu: Bit messy, but we need to 'fix'
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> java.util.Properties here...
if (rawType == Properties.class) {
result = MapType.construct(rawType, bindings, superClass, superInterfaces,
CORE_TYPE_STRING, CORE_TYPE_STRING);
}
// And then check what flavor of type we got. Start by asking resolved
// super-type if refinement is all that is needed?
else if (superClass != null) {
result = superClass.refine(rawType, bindings, superClass, superInterfaces);
}
// if not, perhaps we are now resolving a well-known class or interface?
if (result == null) {
result = _fromWellKnownClass(context, rawType, bindings, superClass, superInterfaces);
if (result == null) {
result = _fromWellKnownInterface(context, rawType, bindings, superClass, superInterfaces);
if (result == null) {
// but if nothing else, "simple" class for now:
result = _newSimpleType(rawType, bindings, superClass, superInterfaces);
}
}
}
}
context.resolveSelfReferences(result);
if (cachable) {
_typeCache.putIfAbsent(rawType, result); // cache object syncs
}
return result;
}
protected JavaType _resolveSuperClass(ClassStack context, Class<?> rawType, TypeBindings parentBindings)
{
Type parent = ClassUtil.getGenericSuperclass(rawType);
if (parent == null) {
return null;
}
return _fromAny(context, parent, parentBindings);
}
protected JavaType[] _resolveSuperInterfaces(ClassStack context, Class<?> rawType, TypeBindings parentBindings)
{
Type[] types = ClassUtil.getGenericInterfaces(rawType);
if (types == null || types.length == 0) {
return NO_TYPES;
}
int len = types.length;
JavaType[] resolved = new JavaType[len];
for (int i = 0; i < len; ++i) {
Type type = types[i];
resolved[i] = _fromAny(context, type, parentBindings);
}
return resolved;
}
/**
* Helper class used to check whether exact class for which type is being constructed
* is one of well-known base
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> interfaces or classes that indicates alternate
* {@link JavaType} implementation.
*/
protected JavaType _fromWellKnownClass(ClassStack context, Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces)
{
// Quite simple when we resolving exact class/interface; start with that
if (rawType == Map.class) {
return _mapType(rawType, bindings, superClass, superInterfaces);
}
if (rawType == Collection.class) {
return _collectionType(rawType, bindings, superClass, superInterfaces);
}
// and since 2.6 one referential type
if (rawType == AtomicReference.class) {
return _referenceType(rawType, bindings, superClass, superInterfaces);
}
// 01-Nov-2015, tatu: As of 2.7, couple of potential `CollectionLikeType`s (like
// `Iterable`, `Iterator`), and `MapLikeType`s (`Map.Entry`) are not automatically
// detected, related to difficulties in propagating type upwards (Iterable, for
// example, is a weak, tag-on type). They may be detectable in future.
return null;
}
protected JavaType _fromWellKnownInterface(ClassStack context, Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces)
{
// But that's not all: may be possible current type actually implements an
// interface type. So...
final int intCount = superInterfaces.length;
for (int i = 0; i < intCount; ++i) {
JavaType result = superInterfaces[i].refine(rawType, bindings, superClass, superInterfaces);
if (result != null) {
return result;
}
}
return null;
}
/**
* This method deals with parameterized types, that is,
* first class generic classes.
*/
protected JavaType _fromParamType(ClassStack context, ParameterizedType ptype,
TypeBindings parentBindings)
{
// Assumption here is we'll always get Class, not one of other Types
Class<?> rawType = (Class<?>) ptype.getRawType();
// 29-Oct-2015, tatu: For performance
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> reasons, let's streamline handling of
// couple of not-so-useful parametric types
if (rawType == CLS_ENUM) {
return CORE_TYPE_ENUM;
}
if (rawType == CLS_COMPARABLE) {
return CORE_TYPE_COMPARABLE;
}
if (rawType == CLS_CLASS) {
return CORE_TYPE_CLASS;
}
// First: what is the actual base type? One odd thing is that 'getRawType'
// returns Type, not Class<?> as one might expect. But let's assume it is
// always of type Class: if not, need to add more code to resolve it to Class.
Type[] args = ptype.getActualTypeArguments();
int paramCount = (args == null) ? 0 : args.length;
JavaType[] pt;
TypeBindings newBindings;
if (paramCount == 0) {
newBindings = EMPTY_BINDINGS;
} else {
pt = new JavaType[paramCount];
for (int i = 0; i < paramCount; ++i) {
pt[i] = _fromAny(context, args[i], parentBindings);
}
newBindings = TypeBindings.create(rawType, pt);
}
return _fromClass(context, rawType, newBindings);
}
protected JavaType _fromArrayType(ClassStack context, GenericArrayType type, TypeBindings bindings)
{
JavaType elementType = _fromAny(context, type.getGenericComponentType(), bindings);
return ArrayType.construct(elementType, bindings);
}
protected JavaType _fromVariable(ClassStack context, TypeVariable<?> var, TypeBindings bindings)
{
// ideally should find it via bindings:
final String name = var.getName();
JavaType type = bindings.findBoundType(name);
if (type != null) {
return type;
}
// but if not, use bounds... note that approach here is simplistic; not taking
// into account possible multiple bounds, nor consider upper bounds.
if (bindings.hasUnbound(name)) {
return CORE_TYPE_OBJECT;
}
bindings = bindings.withUnboundVariable(name);
Type[] bounds = var.getBounds();
return _fromAny(context, bounds[
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Mixins.entrySet()) {
mixIns.put(new ClassKey(en.getKey()), en.getValue());
}
_localMixIns = mixIns;
}
}
public void addLocalDefinition(Class<?> target, Class<?> mixinSource) {
if (_localMixIns == null) {
_localMixIns = new HashMap<ClassKey,Class<?>>();
}
_localMixIns.put(new ClassKey(target), mixinSource);
}
@Override
public SimpleMixInResolver copy() {
ClassIntrospector.MixInResolver overrides = (_overrides == null)
? null : _overrides.copy();
Map<ClassKey,Class<?>> mixIns = (_localMixIns == null)
? null : new HashMap<ClassKey,Class<?>>(_localMixIns);
return new SimpleMixInResolver(overrides, mixIns);
}
@Override
public Class<?> findMixInClassFor(Class<?> cls)
{
Class<?> mixin = (_overrides == null) ? null : _overrides.findMixInClassFor(cls);
if (mixin == null && (_localMixIns != null)) {
mixin = _localMixIns.get(new ClassKey(cls));
}
return mixin;
}
public int localSize() {
return (_localMixIns == null) ? 0 : _localMixIns.size();
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> IllegalArgumentException("Can not deserialize Proxy class "+type.getName()+" as a Bean");
}
/* also: can't deserialize some local classes: static are ok; in-method not;
* other non-static inner classes are ok
*/
typeStr = ClassUtil.isLocalType(type, true);
if (typeStr != null) {
throw new IllegalArgumentException("Can not deserialize Class "+type.getName()+" (of type "+typeStr+") as a Bean");
}
return true;
}
/**
* Helper method that will check whether given raw type is marked as always ignorable
* (for purpose of ignoring properties with type)
*/
protected boolean isIgnorableType(DeserializationConfig config, BeanDescription beanDesc,
Class<?> type, Map<Class<?>,Boolean> ignoredTypes)
{
Boolean status = ignoredTypes.get(type);
if (status != null) {
return status.booleanValue();
}
// 21-Apr-2016, tatu: For 2.8, can specify config overrides
ConfigOverride override = config.findConfigOverride(type);
if (override != null) {
status = override.getIsIgnoredType();
}
if (status == null) {
BeanDescription desc = config.introspectClassAnnotations(type);
status = config.getAnnotationIntrospector().isIgnorableType(desc.getClassInfo());
// We default to 'false', i.e. not ignorable
if (status == null) {
status = Boolean.FALSE;
}
}
ignoredTypes.put(type, status);
return status.booleanValue();
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Provider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode objectNode = createObjectNode();
String schemaType = "any";
String objectProperties = null;
String itemDefinition = null;
if (typeHint != null) {
Class<?> rawClass = TypeFactory.rawClass(typeHint);
if (rawClass.isAnnotationPresent(JsonSerializableSchema.class)) {
JsonSerializableSchema schemaInfo = rawClass.getAnnotation(JsonSerializableSchema.class);
schemaType = schemaInfo.schemaType();
if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaObjectPropertiesDefinition())) {
objectProperties = schemaInfo.schemaObjectPropertiesDefinition();
}
if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaItemDefinition())) {
itemDefinition = schemaInfo.schemaItemDefinition();
}
}
}
/* 19-Mar-2012, tatu: geez, this is butt-ugly abonimation of code...
* really, really should not require back ref to an ObjectMapper.
*/
objectNode.put("type", schemaType);
if (objectProperties != null) {
try {
objectNode.set("properties", _getObjectMapper().readTree(objectProperties));
} catch (IOException e) {
provider.reportMappingProblem("Failed to parse @JsonSerializableSchema.schemaObjectPropertiesDefinition value");
}
}
if (itemDefinition != null) {
try {
objectNode.set("items", _getObjectMapper().readTree(itemDefinition));
} catch (IOException e) {
provider.reportMappingProblem("Failed to parse @JsonSerializableSchema.schemaItemDefinition value");
}
}
// always optional, no need to specify:
//objectNode.put("required", false);
return objectNode;
}
private final static synchronized ObjectMapper _getObjectMapper()
{
ObjectMapper mapper = _mapperReference.get();
if (mapper == null) {
mapper = new ObjectMapper();
_mapperReference.set(mapper);
}
return mapper;
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
visitor.expectAnyFormat(typeHint);
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>serClass,
_config.canOverrideAccessModifiers());
}
}
return (JsonSerializer<Object>) _handleResolvable(ser);
}
/*
/**********************************************************
/* Object Id handling
/**********************************************************
*/
@Override
public WritableObjectId findObjectId(Object forPojo, ObjectIdGenerator<?> generatorType)
{
if (_seenObjectIds == null) {
_seenObjectIds = _createObjectIdMap();
} else {
WritableObjectId oid = _seenObjectIds.get(forPojo);
if (oid != null) {
return oid;
}
}
// Not seen yet; must add an entry, return it. For that, we need generator
ObjectIdGenerator<?> generator = null;
if (_objectIdGenerators == null) {
_objectIdGenerators = new ArrayList<ObjectIdGenerator<?>>(8);
} else {
for (int i = 0, len = _objectIdGenerators.size(); i < len; ++i) {
ObjectIdGenerator<?> gen = _objectIdGenerators.get(i);
if (gen.canUseFor(generatorType)) {
generator = gen;
break;
}
}
}
if (generator == null) {
generator = generatorType.newForSerialization(this);
_objectIdGenerators.add(generator);
}
WritableObjectId oid = new WritableObjectId(generator);
_seenObjectIds.put(forPojo, oid);
return oid;
}
/**
* Overridable helper method used for creating {@link java.util.Map}
* used for storing mappings from serializable objects to their
* Object Ids.
*
* @since 2.3
*/
protected Map<Object,WritableObjectId> _createObjectIdMap()
{
/* 06-Aug-2013, tatu: We may actually want to use equality,
* instead of identity... so:
*/
if (isEnabled(SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID)) {
return new HashMap<Object,WritableObjectId>();
}
return new IdentityHashMap<Object,WritableObjectId>();
}
/*
/**********************************************************
/* Extended API: simple accesors
/**********************************************************
*/
/**
* Method that can be called to see if this serializer provider
* can find a serializer for an instance of
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> represents JSON
* String value
*/
@Override
public TextNode textNode(String text) { return TextNode.valueOf(text); }
/**
* Factory method for constructing a node that represents given
* binary data, and will get serialized as equivalent base64-encoded
* String value
*/
@Override
public BinaryNode binaryNode(byte[] data) { return BinaryNode.valueOf(data); }
/**
* Factory method for constructing a node that represents given
* binary data, and will get serialized as equivalent base64-encoded
* String value
*/
@Override
public BinaryNode binaryNode(byte[] data, int offset, int length) {
return BinaryNode.valueOf(data, offset, length);
}
/*
/**********************************************************
/* Factory method for structured values
/**********************************************************
*/
/**
* Factory method for constructing an empty JSON Array node
*/
@Override
public ArrayNode arrayNode() { return new ArrayNode(this); }
/**
* Factory method for constructing a JSON Array node with an initial capacity
*
* @since 2.8
*/
@Override
public ArrayNode arrayNode(int capacity) { return new ArrayNode(this, capacity); }
/**
* Factory method for constructing an empty JSON Object ("struct") node
*/
@Override
public ObjectNode objectNode() { return new ObjectNode(this); }
/**
* Factory method for constructing a wrapper for POJO
* ("Plain Old Java Object") objects; these will get serialized
* using data binding, usually as JSON Objects, but in some
* cases as JSON Strings or other node types.
*/
@Override
public ValueNode pojoNode(Object pojo) { return new POJONode(pojo); }
@Override
public ValueNode rawValueNode(RawValue value) {
return new POJONode(value);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected boolean _inIntRange(long l)
{
int i = (int) l;
long l2 = (long) i;
return (l2 == l);
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.ext;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
/**
* @since 2.8
*/
public class NioPathDeserializer extends StdScalarDeserializer<Path>
{
private static final long serialVersionUID = 1;
public NioPathDeserializer() { super(Path.class); }
@Override
public Path deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
if (!p.hasToken(JsonToken.VALUE_STRING)) {
return (Path) ctxt.handleUnexpectedToken(Path.class, p);
}
final String value = p.getText();
// If someone gives us an input with no : at all, treat as local path, instead of failing
// with invalid URI.
if (value.indexOf(':') < 0) {
return Paths.get(value);
}
try {
URI uri = new URI(value);
return Paths.get(uri);
} catch (URISyntaxException e) {
return (Path) ctxt.handleInstantiationProblem(handledType(), value, e);
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.ser;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.ser.impl.ReadOnlyClassToSerializerMap;
import com.fasterxml.jackson.databind.util.TypeKey;
/**
* Simple cache object that allows for doing 2-level lookups: first level is
* by "local" read-only lookup Map (used without locking)
* and second backup level is by a shared modifiable HashMap.
* The idea is that after a while, most serializers are found from the
* local Map (to optimize performance, reduce lock contention),
* but that during buildup we can use a shared map to reduce both
* number of distinct read-only maps constructed, and number of
* serializers constructed.
*<p>
* Cache contains three kinds of entries,
* based on combination of class pair key. First class in key is for the
* type to serialize, and second one is type used for determining how
* to resolve value type. One (but not both) of entries can be null.
*/
public final class SerializerCache
{
/**
* Shared, modifiable map; all access needs to be through synchronized blocks.
*<p>
* NOTE: keys are of various types (see below for key types), in addition to
* basic {@link JavaType} used for "untyped" serializers.
*/
private final HashMap<TypeKey, JsonSerializer<Object>> _sharedMap
= new HashMap<TypeKey, JsonSerializer<Object>>(64);
/**
* Most recent read-only instance, created from _sharedMap, if any.
*/
private final AtomicReference<ReadOnlyClassToSerializerMap> _readOnlyMap
= new AtomicReference<ReadOnlyClassToSerializerMap>();
public SerializerCache() { }
/**
* Method that can be called to get a read-only instance populated from the
* most recent version of the shared lookup Map.
*/
public ReadOnlyClassToSerializerMap getReadOnlyLookupMap()
{
ReadOnlyClassToSerializerMap m = _readOnlyMap.get();
if (m != null) {
return m;
}
return _makeReadOnlyLookupMap();
}
private final synchronized ReadOnlyClassToSerializerMap _makeReadOnly
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>LookupMap() {
// double-locking; safe, but is it really needed? Not doing that is only a perf problem,
// not correctness
ReadOnlyClassToSerializerMap m = _readOnlyMap.get();
if (m == null) {
m = ReadOnlyClassToSerializerMap.from(_sharedMap);
_readOnlyMap.set(m);
}
return m;
}
/*
/**********************************************************
/* Lookup methods for accessing shared (slow) cache
/**********************************************************
*/
public synchronized int size() {
return _sharedMap.size();
}
/**
* Method that checks if the shared (and hence, synchronized) lookup Map might have
* untyped serializer for given type.
*/
public JsonSerializer<Object> untypedValueSerializer(Class<?> type)
{
synchronized (this) {
return _sharedMap.get(new TypeKey(type, false));
}
}
public JsonSerializer<Object> untypedValueSerializer(JavaType type)
{
synchronized (this) {
return _sharedMap.get(new TypeKey(type, false));
}
}
public JsonSerializer<Object> typedValueSerializer(JavaType type)
{
synchronized (this) {
return _sharedMap.get(new TypeKey(type, true));
}
}
public JsonSerializer<Object> typedValueSerializer(Class<?> cls)
{
synchronized (this) {
return _sharedMap.get(new TypeKey(cls, true));
}
}
/*
/**********************************************************
/* Methods for adding shared serializer instances
/**********************************************************
*/
/**
* Method called if none of lookups succeeded, and caller had to construct
* a serializer. If so, we will update the shared lookup map so that it
* can be resolved via it next time.
*/
public void addTypedSerializer(JavaType type, JsonSerializer<Object> ser)
{
synchronized (this) {
if (_sharedMap.put(new TypeKey(type, true), ser) == null) {
// let's invalidate the read-only copy, too, to get it updated
_readOnlyMap.set(null);
}
}
}
public void addTypedSerializer(Class<?> cls, JsonSerializer<Object> ser)
{
synchronized (this) {
if (_sharedMap.put(new Type
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Class();
String clsName = raw.getName();
JsonSerializer<?> ser = _concrete.get(clsName);
if (ser == null) {
Class<? extends JsonSerializer<?>> serClass = _concreteLazy.get(clsName);
if (serClass != null) {
try {
return serClass.newInstance();
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate standard serializer (of type "+serClass.getName()+"): "
+e.getMessage(), e);
}
}
}
return ser;
}
/**
* Method called to see if one of primary per-class annotations
* (or related, like implementing of {@link JsonSerializable})
* determines the serializer to use.
*<p>
* Currently handles things like:
*<ul>
* <li>If type implements {@link JsonSerializable}, use that
* </li>
* <li>If type has {@link com.fasterxml.jackson.annotation.JsonValue} annotation (or equivalent), build serializer
* based on that property
* </li>
*</ul>
*
* @since 2.0
*/
protected final JsonSerializer<?> findSerializerByAnnotations(SerializerProvider prov,
JavaType type, BeanDescription beanDesc)
throws JsonMappingException
{
Class<?> raw = type.getRawClass();
// First: JsonSerializable?
if (JsonSerializable.class.isAssignableFrom(raw)) {
return SerializableSerializer.instance;
}
// Second: @JsonValue for any type
AnnotatedMethod valueMethod = beanDesc.findJsonValueMethod();
if (valueMethod != null) {
Method m = valueMethod.getAnnotated();
if (prov.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(m, prov.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
}
JsonSerializer<Object> ser = findSerializerFromAnnotation(prov, valueMethod);
return new JsonValueSerializer(valueMethod, ser);
}
// No well-known annotations...
return null;
}
/**
* Method for checking if we can determine serializer to use based on set of
* known primary types, checking for set of known base types (exact matches
* having been compared against with <code>findSerializerByLookup</code>).
* This does not include "secondary" interfaces
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
@Override // since 2.7
public void setLenient(boolean enabled) {
Boolean newValue = enabled;
if (_lenient != newValue) {
_lenient = newValue;
// and since leniency settings may have been used:
_clearFormats();
}
}
@Override // since 2.7
public boolean isLenient() {
if (_lenient == null) {
// default is, I believe, true
return true;
}
return _lenient.booleanValue();
}
/*
/**********************************************************
/* Public API, parsing
/**********************************************************
*/
@Override
public Date parse(String dateStr) throws ParseException
{
dateStr = dateStr.trim();
ParsePosition pos = new ParsePosition(0);
Date dt;
if (looksLikeISO8601(dateStr)) { // also includes "plain"
dt = parseAsISO8601(dateStr, pos, true);
} else {
// Also consider "stringified" simple time stamp
int i = dateStr.length();
while (--i >= 0) {
char ch = dateStr.charAt(i);
if (ch < '0' || ch > '9') {
// 07-Aug-2013, tatu: And [databind#267] points out that negative numbers should also work
if (i > 0 || ch != '-') {
break;
}
}
}
if ((i < 0)
// let's just assume negative numbers are fine (can't be RFC-1123 anyway); check length for positive
&& (dateStr.charAt(0) == '-' || NumberInput.inLongRange(dateStr, false))) {
dt = new Date(Long.parseLong(dateStr));
} else {
// Otherwise, fall back to using RFC 1123
dt = parseAsRFC1123(dateStr, pos);
}
}
if (dt != null) {
return dt;
}
StringBuilder sb = new StringBuilder();
for (String f : ALL_FORMATS) {
if (sb.length() > 0) {
sb.append("\", \"");
} else {
sb.append('"');
}
sb.append(f
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>);
}
sb.append('"');
throw new ParseException
(String.format("Can not parse date \"%s\": not compatible with any of standard forms (%s)",
dateStr, sb.toString()), pos.getErrorIndex());
}
@Override
public Date parse(String dateStr, ParsePosition pos)
{
if (looksLikeISO8601(dateStr)) { // also includes "plain"
try {
return parseAsISO8601(dateStr, pos, false);
} catch (ParseException e) { // will NOT be thrown due to false but is declared...
return null;
}
}
// Also consider "stringified" simple time stamp
int i = dateStr.length();
while (--i >= 0) {
char ch = dateStr.charAt(i);
if (ch < '0' || ch > '9') {
// 07-Aug-2013, tatu: And [databind#267] points out that negative numbers should also work
if (i > 0 || ch != '-') {
break;
}
}
}
if (i < 0) { // all digits
// let's just assume negative numbers are fine (can't be RFC-1123 anyway); check length for positive
if (dateStr.charAt(0) == '-' || NumberInput.inLongRange(dateStr, false)) {
return new Date(Long.parseLong(dateStr));
}
}
// Otherwise, fall back to using RFC 1123
return parseAsRFC1123(dateStr, pos);
}
/*
/**********************************************************
/* Public API, writing
/**********************************************************
*/
@Override
public StringBuffer format(Date date, StringBuffer toAppendTo,
FieldPosition fieldPosition)
{
if (_formatISO8601 == null) {
_formatISO8601 = _cloneFormat(DATE_FORMAT_ISO8601, DATE_FORMAT_STR_ISO8601,
_timezone, _locale, _lenient);
}
return _formatISO8601.format(date, toAppendTo, fieldPosition);
}
/*
/**********************************************************
/* Std overrides
/**********************************************************
*/
@Override
public String toString()
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> {
String str = "DateFormat "+getClass().getName();
TimeZone tz = _timezone;
if (tz != null) {
str += " (timezone: "+tz+")";
}
str += "(locale: "+_locale+")";
return str;
}
@Override // since 2.7[.2], as per [databind#1130]
public boolean equals(Object o) {
return (o == this);
}
@Override // since 2.7[.2], as per [databind#1130]
public int hashCode() {
return System.identityHashCode(this);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
/**
* Overridable helper method used to figure out which of supported
* formats is the likeliest match.
*/
protected boolean looksLikeISO8601(String dateStr)
{
if (dateStr.length() >= 5
&& Character.isDigit(dateStr.charAt(0))
&& Character.isDigit(dateStr.charAt(3))
&& dateStr.charAt(4) == '-'
) {
return true;
}
return false;
}
protected Date parseAsISO8601(String dateStr, ParsePosition pos, boolean throwErrors)
throws ParseException
{
/* 21-May-2009, tatu: DateFormat has very strict handling of
* timezone modifiers for ISO-8601. So we need to do some scrubbing.
*/
/* First: do we have "zulu" format ('Z' == "UTC")? If yes, that's
* quite simple because we already set date format timezone to be
* UTC, and hence can just strip out 'Z' altogether
*/
int len = dateStr.length();
char c = dateStr.charAt(len-1);
DateFormat df;
String formatStr;
// Need to support "plain" date...
if (len <= 10 && Character.isDigit(c)) {
df = _formatPlain;
formatStr = DATE_FORMAT_STR_PLAIN;
if (df == null) {
df = _formatPlain = _cloneFormat(DATE_FORMAT_PLAIN, formatStr,
_timezone, _locale,
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> _lenient);
}
} else if (c == 'Z') {
df = _formatISO8601_z;
formatStr = DATE_FORMAT_STR_ISO8601_Z;
if (df == null) {
df = _formatISO8601_z = _cloneFormat(DATE_FORMAT_ISO8601_Z, formatStr,
_timezone, _locale, _lenient);
}
// may be missing milliseconds... if so, add
if (dateStr.charAt(len-4) == ':') {
StringBuilder sb = new StringBuilder(dateStr);
sb.insert(len-1, ".000");
dateStr = sb.toString();
}
} else {
// Let's see if we have timezone indicator or not...
if (hasTimeZone(dateStr)) {
c = dateStr.charAt(len-3);
if (c == ':') { // remove optional colon
// remove colon
StringBuilder sb = new StringBuilder(dateStr);
sb.delete(len-3, len-2);
dateStr = sb.toString();
} else if (c == '+' || c == '-') { // missing minutes
// let's just append '00'
dateStr += "00";
}
// Milliseconds partial or missing; and even seconds are optional
len = dateStr.length();
// remove 'T', '+'/'-' and 4-digit timezone-offset
int timeLen = len - dateStr.lastIndexOf('T') - 6;
if (timeLen < 12) { // 8 for hh:mm:ss, 4 for .sss
int offset = len - 5; // insertion offset, before tz-offset
StringBuilder sb = new StringBuilder(dateStr);
switch (timeLen) {
case 11:
sb.insert(offset, '0'); break;
case 10:
sb.insert(offset, "00"); break;
case 9: // is this legal? (just second fraction marker)
sb.insert(offset, "000"); break;
case 8:
sb.insert(offset, ".000"); break;
case 7: // not legal to have single-digit second
break;
case 6: //
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> probably not legal, but let's allow
sb.insert(offset, "00.000");
case 5: // is legal to omit seconds
sb.insert(offset, ":00.000");
}
dateStr = sb.toString();
}
df = _formatISO8601;
formatStr = DATE_FORMAT_STR_ISO8601;
if (_formatISO8601 == null) {
df = _formatISO8601 = _cloneFormat(DATE_FORMAT_ISO8601, formatStr,
_timezone, _locale, _lenient);
}
} else {
// If not, plain date. Easiest to just patch 'Z' in the end?
StringBuilder sb = new StringBuilder(dateStr);
// And possible also millisecond part if missing
int timeLen = len - dateStr.lastIndexOf('T') - 1;
if (timeLen < 12) { // missing, or partial
switch (timeLen) {
case 11: sb.append('0');
case 10: sb.append('0');
case 9: sb.append('0');
break;
default:
sb.append(".000");
}
}
sb.append('Z');
dateStr = sb.toString();
df = _formatISO8601_z;
formatStr = DATE_FORMAT_STR_ISO8601_Z;
if (df == null) {
df = _formatISO8601_z = _cloneFormat(DATE_FORMAT_ISO8601_Z, formatStr,
_timezone, _locale, _lenient);
}
}
}
Date dt = df.parse(dateStr, pos);
// 22-Dec-2015, tatu: With non-lenient, may get null
if (dt == null) {
throw new ParseException
(String.format("Can not parse date \"%s\": while it seems to fit format '%s', parsing fails (leniency? %s)",
dateStr, formatStr, _lenient),
pos.getErrorIndex());
}
return dt;
}
protected Date parseAsRFC1123(String dateStr, ParsePosition
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> pos)
{
if (_formatRFC1123 == null) {
_formatRFC1123 = _cloneFormat(DATE_FORMAT_RFC1123, DATE_FORMAT_STR_RFC1123,
_timezone, _locale, _lenient);
}
return _formatRFC1123.parse(dateStr, pos);
}
private final static boolean hasTimeZone(String str)
{
// Only accept "+hh", "+hhmm" and "+hh:mm" (and with minus), so
int len = str.length();
if (len >= 6) {
char c = str.charAt(len-6);
if (c == '+' || c == '-') return true;
c = str.charAt(len-5);
if (c == '+' || c == '-') return true;
c = str.charAt(len-3);
if (c == '+' || c == '-') return true;
}
return false;
}
private final static DateFormat _cloneFormat(DateFormat df, String format,
TimeZone tz, Locale loc, Boolean lenient)
{
if (!loc.equals(DEFAULT_LOCALE)) {
df = new SimpleDateFormat(format, loc);
df.setTimeZone((tz == null) ? DEFAULT_TIMEZONE : tz);
} else {
df = (DateFormat) df.clone();
if (tz != null) {
df.setTimeZone(tz);
}
}
if (lenient != null) {
df.setLenient(lenient.booleanValue());
}
return df;
}
protected void _clearFormats() {
_formatRFC1123 = null;
_formatISO8601 = null;
_formatISO8601_z = null;
_formatPlain = null;
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> explicit,
SettableBeanProperty[] properties)
{
verifyNonDup(creator, C_PROPS, explicit);
// Better ensure we have no duplicate names either...
if (properties.length > 1) {
HashMap<String,Integer> names = new HashMap<String,Integer>();
for (int i = 0, len = properties.length; i < len; ++i) {
String name = properties[i].getName();
/* [Issue-13]: Need to consider Injectables, which may not have
* a name at all, and need to be skipped
*/
if (name.length() == 0 && properties[i].getInjectableValueId() != null) {
continue;
}
Integer old = names.put(name, Integer.valueOf(i));
if (old != null) {
throw new IllegalArgumentException("Duplicate creator property \""+name+"\" (index "+old+" vs "+i+")");
}
}
}
_propertyBasedArgs = properties;
}
public void addIncompeteParameter(AnnotatedParameter parameter) {
if (_incompleteParameter == null) {
_incompleteParameter = parameter;
}
}
// Bunch of methods deprecated in 2.5, to be removed from 2.6 or later
@Deprecated // since 2.5
public void addStringCreator(AnnotatedWithParams creator) {
addStringCreator(creator, false);
}
@Deprecated // since 2.5
public void addIntCreator(AnnotatedWithParams creator) {
addBooleanCreator(creator, false);
}
@Deprecated // since 2.5
public void addLongCreator(AnnotatedWithParams creator) {
addBooleanCreator(creator, false);
}
@Deprecated // since 2.5
public void addDoubleCreator(AnnotatedWithParams creator) {
addBooleanCreator(creator, false);
}
@Deprecated // since 2.5
public void addBooleanCreator(AnnotatedWithParams creator) {
addBooleanCreator(creator, false);
}
@Deprecated // since 2.5
public void addDelegatingCreator(AnnotatedWithParams creator, CreatorProperty[] injectables) {
addDelegatingCreator(creator, false, injectables);
}
@Deprecated // since 2.5
public void addPropertyCreator(AnnotatedWithParams creator,
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> CreatorProperty[] properties) {
addPropertyCreator(creator, false, properties);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
/**
* @since 2.1
*/
public boolean hasDefaultCreator() {
return _creators[C_DEFAULT] != null;
}
/**
* @since 2.6
*/
public boolean hasDelegatingCreator() {
return _creators[C_DELEGATE] != null;
}
/**
* @since 2.6
*/
public boolean hasPropertyBasedCreator() {
return _creators[C_PROPS] != null;
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
private JavaType _computeDelegateType(AnnotatedWithParams creator,
SettableBeanProperty[] delegateArgs)
{
if (!_hasNonDefaultCreator || (creator == null)) {
return null;
}
// need to find type...
int ix = 0;
if (delegateArgs != null) {
for (int i = 0, len = delegateArgs.length; i < len; ++i) {
if (delegateArgs[i] == null) { // marker for delegate itself
ix = i;
break;
}
}
}
return creator.getParameterType(ix);
}
private <T extends AnnotatedMember> T _fixAccess(T member)
{
if (member != null && _canFixAccess) {
ClassUtil.checkAndFixAccess((Member) member.getAnnotated(), _forceAccess);
}
return member;
}
protected void verifyNonDup(AnnotatedWithParams newOne, int typeIndex, boolean explicit)
{
final int mask = (1 << typeIndex);
_hasNonDefaultCreator = true;
AnnotatedWithParams oldOne = _creators[typeIndex];
// already had an explicitly marked one?
if (oldOne != null) {
boolean verify;
if ((_explicitCreators & mask) != 0) { // already had explicitly annotated, leave as-is
// but skip, if new one not annotated
if (!explicit) {
return;
}
// both explicit: verify
verify = true;
} else {
// otherwise only verify if neither explicitly annotated.
verify = !explicit;
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
if (deser == null) {
deser = _createAndCacheValueDeserializer(ctxt, factory, type);
}
return (deser != null);
}
/*
/**********************************************************
/* Helper methods that handle cache lookups
/**********************************************************
*/
protected JsonDeserializer<Object> _findCachedDeserializer(JavaType type)
{
if (type == null) {
throw new IllegalArgumentException("Null JavaType passed");
}
if (_hasCustomValueHandler(type)) {
return null;
}
return _cachedDeserializers.get(type);
}
/**
* Method that will try to create a deserializer for given type,
* and resolve and cache it if necessary
*
* @param ctxt Currently active deserialization context
* @param type Type of property to deserialize
*/
protected JsonDeserializer<Object> _createAndCacheValueDeserializer(DeserializationContext ctxt,
DeserializerFactory factory, JavaType type)
throws JsonMappingException
{
/* Only one thread to construct deserializers at any given point in time;
* limitations necessary to ensure that only completely initialized ones
* are visible and used.
*/
synchronized (_incompleteDeserializers) {
// Ok, then: could it be that due to a race condition, deserializer can now be found?
JsonDeserializer<Object> deser = _findCachedDeserializer(type);
if (deser != null) {
return deser;
}
int count = _incompleteDeserializers.size();
// Or perhaps being resolved right now?
if (count > 0) {
deser = _incompleteDeserializers.get(type);
if (deser != null) {
return deser;
}
}
// Nope: need to create and possibly cache
try {
return _createAndCache2(ctxt, factory, type);
} finally {
// also: any deserializers that have been created are complete by now
if (count == 0 && _incompleteDeserializers.size() > 0) {
_incompleteDeserializers.clear();
}
}
}
}
/**
* Method that handles actual construction (via factory) and caching (both
* intermediate and eventual)
*/
protected JsonDeserializer<Object> _createAndCache2(DeserializationContext ctxt,
DeserializerFactory factory, JavaType type)
throws
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> value) throws IllegalArgumentException
{
try {
_field.set(pojo, value);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to setValue() for field "
+getFullName()+": "+e.getMessage(), e);
}
}
@Override
public Object getValue(Object pojo) throws IllegalArgumentException
{
try {
return _field.get(pojo);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to getValue() for field "
+getFullName()+": "+e.getMessage(), e);
}
}
/*
/**********************************************************
/* Extended API, generic
/**********************************************************
*/
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName();
}
public int getAnnotationCount() { return _annotations.size(); }
/**
* @since 2.6
*/
public boolean isTransient() { return Modifier.isTransient(getModifiers()); }
@Override
public int hashCode() {
return _field.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedField) o)._field == _field;
}
@Override
public String toString() {
return "[field "+getFullName()+"]";
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedField(new Serialization(_field));
}
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Field f = clazz.getDeclaredField(_serialization.name);
// 06-Oct-2012, tatu: Has "lost" its security override, may need to force back
if (!f.isAccessible()) {
ClassUtil.checkAndFixAccess(f, false);
}
return new AnnotatedField(null, f, null);
} catch (Exception e) {
throw new IllegalArgumentException("Could not find method '"+_serialization.name
+"' from Class '"+clazz.getName());
}
}
/**
* Helper class that is used as the workaround to persist
* Field references. It basically just stores declaring class
* and field name.
*/
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>0".equals(str)) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
protected Byte _parseByte(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return p.getByteValue();
}
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
if (_hasTextualNull(text)) {
return (Byte) getNullValue(ctxt);
}
int value;
try {
int len = text.length();
if (len == 0) {
return (Byte) getEmptyValue(ctxt);
}
value = NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
return (Byte) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid Byte value");
}
// So far so good: but does it fit?
// as per [JACKSON-804], allow range up to 255, inclusive
if (value < Byte.MIN_VALUE || value > 255) {
return (Byte) ctxt.handleWeirdStringValue(_valueClass, text,
"overflow, value can not be represented as 8-bit value");
// fall-through for deferred fails
}
return Byte.valueOf((byte) value);
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Byte");
}
return p.getByteValue();
}
if (t == JsonToken.VALUE_NULL) {
return (Byte) getNullValue(ctxt);
}
// [databind#381]
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Byte parsed = _parseByte(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
handleMissingEndArrayForSingle(p, ctxt);
}
return parsed;
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> return (Byte) ctxt.handleUnexpectedToken(_valueClass, p);
}
protected Short _parseShort(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return p.getShortValue();
}
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
int value;
try {
int len = text.length();
if (len == 0) {
return (Short) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Short) getNullValue(ctxt);
}
value = NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
return (Short) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid Short value");
}
// So far so good: but does it fit?
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
return (Short) ctxt.handleWeirdStringValue(_valueClass, text,
"overflow, value can not be represented as 16-bit value");
}
return Short.valueOf((short) value);
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Short");
}
return p.getShortValue();
}
if (t == JsonToken.VALUE_NULL) {
return (Short) getNullValue(ctxt);
}
// [databind#381]
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Short parsed = _parseShort(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
handleMissingEndArrayForSingle(p, ctxt);
}
return parsed;
}
return (Short) ctxt.handleUnexpectedToken(_valueClass, p);
}
protected final short _parseShortPrimitive(JsonParser p, DeserializationContext
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> ctxt)
throws IOException
{
int value = _parseIntPrimitive(p, ctxt);
// So far so good: but does it fit?
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
Number v = (Number) ctxt.handleWeirdStringValue(_valueClass, String.valueOf(value),
"overflow, value can not be represented as 16-bit value");
return (v == null) ? (short) 0 : v.shortValue();
}
return (short) value;
}
protected final int _parseIntPrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
return p.getIntValue();
}
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
if (_hasTextualNull(text)) {
return 0;
}
try {
int len = text.length();
if (len > 9) {
long l = Long.parseLong(text);
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
Number v = (Number) ctxt.handleWeirdStringValue(_valueClass, text,
"Overflow: numeric value (%s) out of range of int (%d -%d)",
text, Integer.MIN_VALUE, Integer.MAX_VALUE);
return (v == null) ? 0 : v.intValue();
}
return (int) l;
}
if (len == 0) {
return 0;
}
return NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
Number v = (Number) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid int value");
return (v == null) ? 0 : v.intValue();
}
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "int");
}
return p.getValueAsInt();
}
if (t == JsonToken
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>.VALUE_NULL) {
return 0;
}
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final int parsed = _parseIntPrimitive(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
handleMissingEndArrayForSingle(p, ctxt);
}
return parsed;
}
// Otherwise, no can do:
return ((Number) ctxt.handleUnexpectedToken(_valueClass, p)).intValue();
}
protected final Integer _parseInteger(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
// NOTE: caller assumed to usually check VALUE_NUMBER_INT in fast path
case JsonTokenId.ID_NUMBER_INT:
return Integer.valueOf(p.getIntValue());
case JsonTokenId.ID_NUMBER_FLOAT: // coercing may work too
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Integer");
}
return Integer.valueOf(p.getValueAsInt());
case JsonTokenId.ID_STRING: // let's do implicit re-parse
String text = p.getText().trim();
try {
int len = text.length();
if (_hasTextualNull(text)) {
return (Integer) getNullValue(ctxt);
}
if (len > 9) {
long l = Long.parseLong(text);
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
return (Integer) ctxt.handleWeirdStringValue(_valueClass, text,
"Overflow: numeric value ("+text+") out of range of Integer ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")");
// fall-through
}
return Integer.valueOf((int) l);
}
if (len == 0) {
return (Integer) getEmptyValue(ctxt);
}
return Integer.valueOf(NumberInput.parseInt(text));
} catch (IllegalArgumentException iae) {
return (Integer) ctxt.handleWeirdStringValue(_valueClass, text,
"not a valid Integer value");
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
}
if (DeserializationFeature.USE_LONG_FOR_INTS.enabledIn(feats)) {
return p.getLongValue();
}
return p.getBigIntegerValue(); // should be optimal, whatever it is
}
/*
/****************************************************
/* Helper methods for sub-classes, resolving dependencies
/****************************************************
*/
/**
* Helper method used to locate deserializers for properties the
* type this deserializer handles contains (usually for properties of
* bean types)
*
* @param type Type of property to deserialize
* @param property Actual property object (field, method, constuctor parameter) used
* for passing deserialized values; provided so deserializer can be contextualized if necessary
*/
protected JsonDeserializer<Object> findDeserializer(DeserializationContext ctxt,
JavaType type, BeanProperty property)
throws JsonMappingException
{
return ctxt.findContextualValueDeserializer(type, property);
}
/**
* Helper method to check whether given text refers to what looks like a clean simple
* integer number, consisting of optional sign followed by a sequence of digits.
*/
protected final boolean _isIntNumber(String text)
{
final int len = text.length();
if (len > 0) {
char c = text.charAt(0);
// skip leading sign (plus not allowed for strict JSON numbers but...)
int i = (c == '-' || c == '+') ? 1 : 0;
for (; i < len; ++i) {
int ch = text.charAt(i);
if (ch > '9' || ch < '0') {
return false;
}
}
return true;
}
return false;
}
/*
/**********************************************************
/* Helper methods for sub-classes, deserializer construction
/**********************************************************
*/
/**
* Helper method that can be used to see if specified property has annotation
* indicating that a converter is to be used for contained values (contents
* of structured types; array/List/Map values)
*
* @param existingDeserializer (optional) configured content
* serializer if one already exists.
*
* @since 2.2
*/
protected JsonDeserializer<?> findConvertingContentDeserializer(DeserializationContext ctxt,
BeanProperty prop, JsonDeserializer<?> existingDeserializer)
throws JsonMappingException
{
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.type;
import java.lang.reflect.*;
import java.util.*;
import com.fasterxml.jackson.databind.JavaType;
/**
* Helper class used for resolving type parameters for given class
*/
public class TypeBindings
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
private final static String[] NO_STRINGS = new String[0];
private final static JavaType[] NO_TYPES = new JavaType[0];
private final static TypeBindings EMPTY = new TypeBindings(NO_STRINGS, NO_TYPES, null);
// // // Pre-resolved instances for minor optimizations
// // // Actual member information
/**
* Array of type (type variable) names.
*/
private final String[] _names;
/**
* Types matching names
*/
private final JavaType[] _types;
/**
* Names of potentially unresolved type variables.
*
* @since 2.3
*/
private final String[] _unboundVariables;
private final int _hashCode;
/*
/**********************************************************************
/* Construction
/**********************************************************************
*/
private TypeBindings(String[] names, JavaType[] types, String[] uvars)
{
_names = (names == null) ? NO_STRINGS : names;
_types = (types == null) ? NO_TYPES : types;
if (_names.length != _types.length) {
throw new IllegalArgumentException("Mismatching names ("+_names.length+"), types ("+_types.length+")");
}
int h = 1;
for (int i = 0, len = _types.length; i < len; ++i) {
h += _types[i].hashCode();
}
_unboundVariables = uvars;
_hashCode = h;
}
public static TypeBindings emptyBindings() {
return EMPTY;
}
// Let's just canonicalize serialized EMPTY back to static instance, if need be
protected Object readResolve() {
if ((_names == null) || (_names.length == 0)) {
return EMPTY;
}
return this;
}
/**
* Factory method for constructing bindings for given class using specified type
* parameters.
*/
public static TypeBindings create(Class<?> erasedType, List<
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>JavaType> typeList)
{
JavaType[] types = (typeList == null || typeList.isEmpty()) ?
NO_TYPES : typeList.toArray(new JavaType[typeList.size()]);
return create(erasedType, types);
}
public static TypeBindings create(Class<?> erasedType, JavaType[] types)
{
if (types == null) {
types = NO_TYPES;
} else switch (types.length) {
case 1:
return create(erasedType, types[0]);
case 2:
return create(erasedType, types[0], types[1]);
}
TypeVariable<?>[] vars = erasedType.getTypeParameters();
String[] names;
if (vars == null || vars.length == 0) {
names = NO_STRINGS;
} else {
int len = vars.length;
names = new String[len];
for (int i = 0; i < len; ++i) {
names[i] = vars[i].getName();
}
}
// Check here to give better error message
if (names.length != types.length) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with "+types.length+" type parameter"
+((types.length == 1) ? "" : "s")+": class expects "+names.length);
}
return new TypeBindings(names, types, null);
}
public static TypeBindings create(Class<?> erasedType, JavaType typeArg1)
{
// 30-Oct-2015, tatu: Minor optimization for relatively common cases
TypeVariable<?>[] vars = TypeParamStash.paramsFor1(erasedType);
int varLen = (vars == null) ? 0 : vars.length;
if (varLen != 1) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with 1 type parameter: class expects "+varLen);
}
return new TypeBindings(new String[] { vars[0].getName() },
new JavaType[] { typeArg1 }, null);
}
public static TypeBindings create(Class<?> erasedType, JavaType typeArg1, JavaType typeArg
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>2)
{
// 30-Oct-2015, tatu: Minor optimization for relatively common cases
TypeVariable<?>[] vars = TypeParamStash.paramsFor2(erasedType);
int varLen = (vars == null) ? 0 : vars.length;
if (varLen != 2) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with 2 type parameters: class expects "+varLen);
}
return new TypeBindings(new String[] { vars[0].getName(), vars[1].getName() },
new JavaType[] { typeArg1, typeArg2 }, null);
}
/**
* Alternate factory method that may be called if it is possible that type
* does or does not require type parameters; this is mostly useful for
* collection- and map-like types.
*/
public static TypeBindings createIfNeeded(Class<?> erasedType, JavaType typeArg1)
{
TypeVariable<?>[] vars = erasedType.getTypeParameters();
int varLen = (vars == null) ? 0 : vars.length;
if (varLen == 0) {
return EMPTY;
}
if (varLen != 1) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with 1 type parameter: class expects "+varLen);
}
return new TypeBindings(new String[] { vars[0].getName() },
new JavaType[] { typeArg1 }, null);
}
/**
* Alternate factory method that may be called if it is possible that type
* does or does not require type parameters; this is mostly useful for
* collection- and map-like types.
*/
public static TypeBindings createIfNeeded(Class<?> erasedType, JavaType[] types)
{
TypeVariable<?>[] vars = erasedType.getTypeParameters();
if (vars == null || vars.length == 0) {
return EMPTY;
}
if (types == null) {
types = NO_TYPES;
}
int len = vars.length;
String[] names = new String[len];
for (int i = 0; i < len; ++i) {
names[i] = vars[i].getName();
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> // Check here to give better error message
if (names.length != types.length) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with "+types.length+" type parameter"
+((types.length == 1) ? "" : "s")+": class expects "+names.length);
}
return new TypeBindings(names, types, null);
}
/**
* Method for creating an instance that has same bindings as this object,
* plus an indicator for additional type variable that may be unbound within
* this context; this is needed to resolve recursive self-references.
*/
public TypeBindings withUnboundVariable(String name)
{
int len = (_unboundVariables == null) ? 0 : _unboundVariables.length;
String[] names = (len == 0)
? new String[1] : Arrays.copyOf(_unboundVariables, len+1);
names[len] = name;
return new TypeBindings(_names, _types, names);
}
/*
/**********************************************************************
/* Accessors
/**********************************************************************
*/
/**
* Find type bound to specified name, if there is one; returns bound type if so, null if not.
*/
public JavaType findBoundType(String name)
{
for (int i = 0, len = _names.length; i < len; ++i) {
if (name.equals(_names[i])) {
JavaType t = _types[i];
if (t instanceof ResolvedRecursiveType) {
ResolvedRecursiveType rrt = (ResolvedRecursiveType) t;
JavaType t2 = rrt.getSelfReferencedType();
if (t2 != null) {
t = t2;
} else {
/* 25-Feb-2016, tatu: Looks like a potential problem, but alas
* we have a test where this should NOT fail and things... seem
* to work. So be it.
*/
/*
throw new IllegalStateException(String.format
("Unresolved ResolvedRecursiveType for parameter '%s' (index #%d; erased type %s)",
name, i, t.getRawClass()));
*/
}
}
return t;
}
}
return null;
}
public
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> boolean isEmpty() {
return (_types.length == 0);
}
/**
* Returns number of bindings contained
*/
public int size() {
return _types.length;
}
public String getBoundName(int index)
{
if (index < 0 || index >= _names.length) {
return null;
}
return _names[index];
}
public JavaType getBoundType(int index)
{
if (index < 0 || index >= _types.length) {
return null;
}
return _types[index];
}
/**
* Accessor for getting bound types in declaration order
*/
public List<JavaType> getTypeParameters()
{
if (_types.length == 0) {
return Collections.emptyList();
}
return Arrays.asList(_types);
}
/**
* @since 2.3
*/
public boolean hasUnbound(String name) {
if (_unboundVariables != null) {
for (int i = _unboundVariables.length; --i >= 0; ) {
if (name.equals(_unboundVariables[i])) {
return true;
}
}
}
return false;
}
/*
/**********************************************************************
/* Standard methods
/**********************************************************************
*/
@Override public String toString()
{
if (_types.length == 0) {
return "";
}
StringBuilder sb = new StringBuilder();
sb.append('<');
for (int i = 0, len = _types.length; i < len; ++i) {
if (i > 0) {
sb.append(',');
}
// sb = _types[i].appendBriefDescription(sb);
String sig = _types[i].getGenericSignature();
sb.append(sig);
}
sb.append('>');
return sb.toString();
}
@Override public int hashCode() { return _hashCode; }
@Override public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
TypeBindings other = (TypeBindings) o;
int len = _types.length;
if (len != other.size()) {
return false;
}
JavaType[] otherTypes
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> = other._types;
for (int i = 0; i < len; ++i) {
if (!otherTypes[i].equals(_types[i])) {
return false;
}
}
return true;
}
/*
/**********************************************************************
/* Package accessible methods
/**********************************************************************
*/
protected JavaType[] typeParameterArray() {
return _types;
}
/*
/**********************************************************************
/* Helper classes
/**********************************************************************
*/
// 30-Oct-2015, tatu: Surprising, but looks like type parameters access can be bit of
// a hot spot. So avoid for a small number of common generic types. Note that we do
// need both common abstract types and concrete ones; latter for specialization
/**
* Helper class that contains simple logic for avoiding repeated lookups via
* {@link Class#getTypeParameters()} as that can be a performance issue for
* some use cases (wasteful, usually one-off or not reusing mapper).
* Partly isolated to avoid initialization for cases where no generic types are
* used.
*/
static class TypeParamStash {
private final static TypeVariable<?>[] VARS_ABSTRACT_LIST = AbstractList.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_COLLECTION = Collection.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_ITERABLE = Iterable.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_LIST = List.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_ARRAY_LIST = ArrayList.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_MAP = Map.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_HASH_MAP = HashMap.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_LINKED_HASH_MAP = LinkedHashMap.class.getTypeParameters();
public static TypeVariable<?>[] paramsFor1(Class<?> erasedType)
{
if (erasedType == Collection.class) {
return VARS_COLLECTION;
}
if (erasedType == List.class) {
return VARS_LIST;
}
if (erasedType == ArrayList.class) {
return VARS_ARRAY_LIST;
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 32-bit integer values.
*/
public class IntNode
extends NumericNode
{
// // // Let's cache small set of common value
final static int MIN_CANONICAL = -1;
final static int MAX_CANONICAL = 10;
private final static IntNode[] CANONICALS;
static {
int count = MAX_CANONICAL - MIN_CANONICAL + 1;
CANONICALS = new IntNode[count];
for (int i = 0; i < count; ++i) {
CANONICALS[i] = new IntNode(MIN_CANONICAL + i);
}
}
/**
* Integer value this node contains
*/
protected final int _value;
/*
************************************************
* Construction
************************************************
*/
public IntNode(int v) { _value = v; }
public static IntNode valueOf(int i) {
if (i > MAX_CANONICAL || i < MIN_CANONICAL) return new IntNode(i);
return CANONICALS[i - MIN_CANONICAL];
}
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.INT; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isInt() { return true; }
@Override public boolean canConvertToInt() { return true; }
@Override public boolean canConvertToLong() { return true; }
@Override
public Number numberValue() {
return Integer.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> * a {@link com.fasterxml.jackson.databind.node.NullNode} will be returned,
* not null.
*
* @return Node that represent value of the specified element,
* if this node is an array and has specified element.
* Null otherwise.
*/
@Override
public abstract JsonNode get(int index);
/**
* Method for accessing value of the specified field of
* an object node. If this node is not an object (or it
* does not have a value for specified field name), or
* if there is no field with such name, null is returned.
*<p>
* NOTE: if the property value has been explicitly set as <code>null</code>
* (which is different from removal!),
* a {@link com.fasterxml.jackson.databind.node.NullNode} will be returned,
* not null.
*
* @return Node that represent value of the specified field,
* if this node is an object and has value for the specified
* field. Null otherwise.
*/
@Override
public JsonNode get(String fieldName) { return null; }
/**
* This method is similar to {@link #get(String)}, except
* that instead of returning null if no such value exists (due
* to this node not being an object, or object not having value
* for the specified field),
* a "missing node" (node that returns true for
* {@link #isMissingNode}) will be returned. This allows for
* convenient and safe chained access via path calls.
*/
@Override
public abstract JsonNode path(String fieldName);
/**
* This method is similar to {@link #get(int)}, except
* that instead of returning null if no such element exists (due
* to index being out of range, or this node not being an array),
* a "missing node" (node that returns true for
* {@link #isMissingNode}) will be returned. This allows for
* convenient and safe chained access via path calls.
*/
@Override
public abstract JsonNode path(int index);
@Override
public Iterator<String> fieldNames() {
return ClassUtil.emptyIterator();
}
/**
* Method for locating node specified by given JSON pointer instances.
* Method will never return null; if no matching
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> *</pre>
* (since return value of get() is node, not value node contains)
*<p>
* NOTE: when explicit <code>null</code> values are added, this
* method will return <code>true</code> for such properties.
*
* @param fieldName Name of element to check
*
* @return True if this node is a JSON Object node, and has a property
* entry with specified name (with any value, including null value)
*/
public boolean has(String fieldName) {
return get(fieldName) != null;
}
/**
* Method that allows checking whether this node is JSON Array node
* and contains a value for specified index
* If this is the case
* (including case of specified indexing having null as value), returns true;
* otherwise returns false.
*<p>
* Note: array element indexes are 0-based.
*<p>
* This method is equivalent to:
*<pre>
* node.get(index) != null
*</pre>
*<p>
* NOTE: this method will return <code>true</code> for explicitly added
* null values.
*
* @param index Index to check
*
* @return True if this node is a JSON Object node, and has a property
* entry with specified name (with any value, including null value)
*/
public boolean has(int index) {
return get(index) != null;
}
/**
* Method that is similar to {@link #has(String)}, but that will
* return <code>false</code> for explicitly added nulls.
*<p>
* This method is functionally equivalent to:
*<pre>
* node.get(fieldName) != null << !node.get(fieldName).isNull()
*</pre>
*
* @since 2.1
*/
public boolean hasNonNull(String fieldName) {
JsonNode n = get(fieldName);
return (n != null) && !n.isNull();
}
/**
* Method that is similar to {@link #has(int)}, but that will
* return <code>false</code> for explicitly added nulls.
*<p>
* This method is equivalent to:
*<
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>pre>
* node.get(index) != null << !node.get(index).isNull()
*</pre>
*
* @since 2.1
*/
public boolean hasNonNull(int index) {
JsonNode n = get(index);
return (n != null) && !n.isNull();
}
/*
/**********************************************************
/* Public API, container access
/**********************************************************
*/
/**
* Same as calling {@link #elements}; implemented so that
* convenience "for-each" loop can be used for looping over elements
* of JSON Array constructs.
*/
@Override
public final Iterator<JsonNode> iterator() { return elements(); }
/**
* Method for accessing all value nodes of this Node, iff
* this node is a JSON Array or Object node. In case of Object node,
* field names (keys) are not included, only values.
* For other types of nodes, returns empty iterator.
*/
public Iterator<JsonNode> elements() {
return ClassUtil.emptyIterator();
}
/**
* @return Iterator that can be used to traverse all key/value pairs for
* object nodes; empty iterator (no contents) for other types
*/
public Iterator<Map.Entry<String, JsonNode>> fields() {
return ClassUtil.emptyIterator();
}
/*
/**********************************************************
/* Public API, find methods
/**********************************************************
*/
/**
* Method for finding a JSON Object field with specified name in this
* node or its child nodes, and returning value it has.
* If no matching field is found in this node or its descendants, returns null.
*
* @param fieldName Name of field to look for
*
* @return Value of first matching node found, if any; null if none
*/
public abstract JsonNode findValue(String fieldName);
/**
* Method for finding JSON Object fields with specified name, and returning
* found ones as a List. Note that sub-tree search ends if a field is found,
* so possible children of result nodes are <b>not</b> included.
* If no matching fields are found in this node or its descendants, returns
* an empty List.
*
* @param fieldName Name of field to look for
*/
public final List<JsonNode> findValues(String
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>>
* NOTE: typed as Object-to-Object, unlike {@link #_shared}, because
* we need to be able to modify contents, and wildcard type would
* complicate that access.
*/
protected transient Map<Object,Object> _nonShared;
/*
/**********************************************************
/* Construction, factory methods
/**********************************************************
*/
protected Impl(Map<?,?> shared) {
_shared = shared;
_nonShared = null;
}
protected Impl(Map<?,?> shared, Map<Object,Object> nonShared) {
_shared = shared;
_nonShared = nonShared;
}
public static ContextAttributes getEmpty() {
return EMPTY;
}
/*
/**********************************************************
/* Per-reader/writer mutant factories
/**********************************************************
*/
@Override
public ContextAttributes withSharedAttribute(Object key, Object value)
{
Map<Object,Object> m;
// need to cover one special case, since EMPTY uses Immutable map:
if (this == EMPTY) {
m = new HashMap<Object,Object>(8);
} else {
m = _copy(_shared);
}
m.put(key, value);
return new Impl(m);
}
@Override
public ContextAttributes withSharedAttributes(Map<?,?> shared) {
return new Impl(shared);
}
@Override
public ContextAttributes withoutSharedAttribute(Object key)
{
// first couple of trivial optimizations
if (_shared.isEmpty()) {
return this;
}
if (_shared.containsKey(key)) {
if (_shared.size() == 1) {
return EMPTY;
}
} else { // if we didn't have it anyway, return as-is
return this;
}
// otherwise make copy, modify
Map<Object,Object> m = _copy(_shared);
m.remove(key);
return new Impl(m);
}
/*
/**********************************************************
/* Per-call access
/**********************************************************
*/
@Override
public Object getAttribute(Object key)
{
if (_nonShared != null) {
Object ob = _nonShared.get(key);
if (ob != null) {
if (ob == NULL_SURROGATE) {
return null;
}
return ob
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>;
}
}
return _shared.get(key);
}
@Override
public ContextAttributes withPerCallAttribute(Object key, Object value)
{
// First: null value may need masking
if (value == null) {
// need to mask nulls to ensure default values won't be showing
if (_shared.containsKey(key)) {
value = NULL_SURROGATE;
} else if ((_nonShared == null) || !_nonShared.containsKey(key)) {
// except if non-mutable shared list has no entry, we don't care
return this;
} else {
_nonShared.remove(key);
return this;
}
}
// a special case: create non-shared instance if need be
if (_nonShared == null) {
return nonSharedInstance(key, value);
}
_nonShared.put(key, value);
return this;
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
/**
* Overridable method that creates initial non-shared instance,
* with the first explicit set value.
*/
protected ContextAttributes nonSharedInstance(Object key, Object value)
{
Map<Object,Object> m = new HashMap<Object,Object>();
if (value == null) {
value = NULL_SURROGATE;
}
m.put(key, value);
return new Impl(_shared, m);
}
private Map<Object,Object> _copy(Map<?,?> src)
{
return new HashMap<Object,Object>(src);
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.util;
import java.lang.annotation.Annotation;
/**
* Interface that defines interface for accessing contents of a
* collection of annotations. This is needed when introspecting
* annotation-based features from different kinds of things, not
* just objects that Java Reflection interface exposes.
*<p>
* Standard mutable implementation is {@link com.fasterxml.jackson.databind.introspect.AnnotationMap}
*/
public interface Annotations
{
/**
* Main access method used to find value for given annotation.
*/
public <A extends Annotation> A get(Class<A> cls);
/**
* Returns number of annotation entries in this collection.
*/
public int size();
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
_filteredProps = filteredProperties;
_typeId = src._typeId;
_anyGetterWriter = src._anyGetterWriter;
_objectIdWriter = src._objectIdWriter;
_propertyFilterId = src._propertyFilterId;
_serializationShape = src._serializationShape;
}
protected BeanSerializerBase(BeanSerializerBase src,
ObjectIdWriter objectIdWriter)
{
this(src, objectIdWriter, src._propertyFilterId);
}
/**
* @since 2.3
*/
protected BeanSerializerBase(BeanSerializerBase src,
ObjectIdWriter objectIdWriter, Object filterId)
{
super(src._handledType);
_props = src._props;
_filteredProps = src._filteredProps;
_typeId = src._typeId;
_anyGetterWriter = src._anyGetterWriter;
_objectIdWriter = objectIdWriter;
_propertyFilterId = filterId;
_serializationShape = src._serializationShape;
}
@Deprecated // since 2.8, remove soon
protected BeanSerializerBase(BeanSerializerBase src, String[] toIgnore)
{
this(src, ArrayBuilders.arrayToSet(toIgnore));
}
protected BeanSerializerBase(BeanSerializerBase src, Set<String> toIgnore)
{
super(src._handledType);
final BeanPropertyWriter[] propsIn = src._props;
final BeanPropertyWriter[] fpropsIn = src._filteredProps;
final int len = propsIn.length;
ArrayList<BeanPropertyWriter> propsOut = new ArrayList<BeanPropertyWriter>(len);
ArrayList<BeanPropertyWriter> fpropsOut = (fpropsIn == null) ? null : new ArrayList<BeanPropertyWriter>(len);
for (int i = 0; i < len; ++i) {
BeanPropertyWriter bpw = propsIn[i];
// should be ignored?
if ((toIgnore != null) && toIgnore.contains(bpw.getName())) {
continue;
}
propsOut.add(bpw);
if (fpropsIn != null) {
fpropsOut.add(fpropsIn[i]);
}
}
_props = propsOut.toArray(new BeanPropertyWriter[propsOut.size()]);
_filteredProps = (fpropsOut == null) ? null : fprops
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>(src._filteredProps, unwrapper));
}
private final static BeanPropertyWriter[] rename(BeanPropertyWriter[] props,
NameTransformer transformer)
{
if (props == null || props.length == 0 || transformer == null || transformer == NameTransformer.NOP) {
return props;
}
final int len = props.length;
BeanPropertyWriter[] result = new BeanPropertyWriter[len];
for (int i = 0; i < len; ++i) {
BeanPropertyWriter bpw = props[i];
if (bpw != null) {
result[i] = bpw.rename(transformer);
}
}
return result;
}
/*
/**********************************************************
/* Post-constriction processing: resolvable, contextual
/**********************************************************
*/
/**
* We need to implement {@link ResolvableSerializer} to be able to
* properly handle cyclic type references.
*/
@Override
public void resolve(SerializerProvider provider)
throws JsonMappingException
{
int filteredCount = (_filteredProps == null) ? 0 : _filteredProps.length;
for (int i = 0, len = _props.length; i < len; ++i) {
BeanPropertyWriter prop = _props[i];
// let's start with null serializer resolution actually
if (!prop.willSuppressNulls() && !prop.hasNullSerializer()) {
JsonSerializer<Object> nullSer = provider.findNullValueSerializer(prop);
if (nullSer != null) {
prop.assignNullSerializer(nullSer);
// also: remember to replace filtered property too? (see [JACKSON-364])
if (i < filteredCount) {
BeanPropertyWriter w2 = _filteredProps[i];
if (w2 != null) {
w2.assignNullSerializer(nullSer);
}
}
}
}
if (prop.hasSerializer()) {
continue;
}
// [databind#124]: allow use of converters
JsonSerializer<Object> ser = findConvertingSerializer(provider, prop);
if (ser == null) {
// Was the serialization type hard-coded? If so, use it
JavaType type = prop.getSerializationType();
// It not, we can use declared return type if and only if declared type
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> is final:
// if not, we don't really know the actual type until we get the instance.
if (type == null) {
// 30-Oct-2015, tatu: Not sure why this was used
// type = provider.constructType(prop.getGenericPropertyType());
// but this looks better
type = prop.getType();
if (!type.isFinal()) {
if (type.isContainerType() || type.containedTypeCount() > 0) {
prop.setNonTrivialBaseType(type);
}
continue;
}
}
ser = provider.findValueSerializer(type, prop);
/* 04-Feb-2010, tatu: We may have stashed type serializer for content types
* too, earlier; if so, it's time to connect the dots here:
*/
if (type.isContainerType()) {
TypeSerializer typeSer = type.getContentType().getTypeHandler();
if (typeSer != null) {
// for now, can do this only for standard containers...
if (ser instanceof ContainerSerializer<?>) {
// ugly casts... but necessary
@SuppressWarnings("unchecked")
JsonSerializer<Object> ser2 = (JsonSerializer<Object>)((ContainerSerializer<?>) ser).withValueTypeSerializer(typeSer);
ser = ser2;
}
}
}
}
prop.assignSerializer(ser);
// and maybe replace filtered property too? (see [JACKSON-364])
if (i < filteredCount) {
BeanPropertyWriter w2 = _filteredProps[i];
if (w2 != null) {
w2.assignSerializer(ser);
}
}
}
// also, any-getter may need to be resolved
if (_anyGetterWriter != null) {
// 23-Feb-2015, tatu: Misleading, as this actually triggers call to contextualization...
_anyGetterWriter.resolve(provider);
}
}
/**
* Helper method that can be used to see if specified property is annotated
* to indicate use of a converter for property value (in case of container types,
* it is container type itself, not key or content type).
*
* @since 2.2
*/
protected JsonSerializer<Object>
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>, property);
}
}
}
}
ObjectIdWriter oiw = _objectIdWriter;
Set<String> ignoredProps = null;
Object newFilterId = null;
// Then we may have an override for Object Id
if (accessor != null) {
JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(accessor);
if (ignorals != null) {
ignoredProps = ignorals.findIgnoredForSerialization();
}
ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor);
if (objectIdInfo == null) {
// no ObjectId override, but maybe ObjectIdRef?
if (oiw != null) {
objectIdInfo = intr.findObjectReferenceInfo(accessor,
new ObjectIdInfo(NAME_FOR_OBJECT_REF, null, null, null));
oiw = _objectIdWriter.withAlwaysAsId(objectIdInfo.getAlwaysAsId());
}
} else {
/* Ugh: mostly copied from BeanSerializerBase: but can't easily
* change it to be able to move to SerializerProvider (where it
* really belongs)
*/
// 2.1: allow modifications by "id ref" annotations as well:
objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo);
ObjectIdGenerator<?> gen;
Class<?> implClass = objectIdInfo.getGeneratorType();
JavaType type = provider.constructType(implClass);
JavaType idType = provider.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0];
// Property-based generator is trickier
if (implClass == ObjectIdGenerators.PropertyGenerator.class) { // most special one, needs extra work
String propName = objectIdInfo.getPropertyName().getSimpleName();
BeanPropertyWriter idProp = null;
for (int i = 0, len = _props.length ;; ++i) {
if (i == len) {
throw new IllegalArgumentException("Invalid Object Id definition for "+_handledType.getName()
+": can not find property with name '"+propName+"'");
}
BeanPropertyWriter prop = _props[i];
if (propName.equals(prop.getName())) {
idProp = prop;
/* Let's force it to be the first property to output
* (although it may still get rearrange
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>d etc)
*/
if (i > 0) { // note: must shuffle both regular properties and filtered
System.arraycopy(_props, 0, _props, 1, i);
_props[0] = idProp;
if (_filteredProps != null) {
BeanPropertyWriter fp = _filteredProps[i];
System.arraycopy(_filteredProps, 0, _filteredProps, 1, i);
_filteredProps[0] = fp;
}
}
break;
}
}
idType = idProp.getType();
gen = new PropertyBasedObjectIdGenerator(objectIdInfo, idProp);
oiw = ObjectIdWriter.construct(idType, (PropertyName) null, gen, objectIdInfo.getAlwaysAsId());
} else { // other types need to be simpler
gen = provider.objectIdGeneratorInstance(accessor, objectIdInfo);
oiw = ObjectIdWriter.construct(idType, objectIdInfo.getPropertyName(), gen,
objectIdInfo.getAlwaysAsId());
}
}
// Or change Filter Id in use?
Object filterId = intr.findFilterId(accessor);
if (filterId != null) {
// but only consider case of adding a new filter id (no removal via annotation)
if (_propertyFilterId == null || !filterId.equals(_propertyFilterId)) {
newFilterId = filterId;
}
}
}
// either way, need to resolve serializer:
BeanSerializerBase contextual = this;
if (oiw != null) {
JsonSerializer<?> ser = provider.findValueSerializer(oiw.idType, property);
oiw = oiw.withSerializer(ser);
if (oiw != _objectIdWriter) {
contextual = contextual.withObjectIdWriter(oiw);
}
}
// And possibly add more properties to ignore
if ((ignoredProps != null) && !ignoredProps.isEmpty()) {
contextual = contextual.withIgnorals(ignoredProps);
}
if (newFilterId != null) {
contextual = contextual.withFilterId(newFilterId);
}
if (shape == null) {
shape = _serializationShape;
}
if (shape == JsonFormat.Shape.ARRAY) {
return contextual.asArraySerializer();
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
}
return (typeId instanceof String) ? (String) typeId : typeId.toString();
}
/*
/**********************************************************
/* Field serialization methods
/**********************************************************
*/
protected void serializeFields(Object bean, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final BeanPropertyWriter[] props;
if (_filteredProps != null && provider.getActiveView() != null) {
props = _filteredProps;
} else {
props = _props;
}
int i = 0;
try {
for (final int len = props.length; i < len; ++i) {
BeanPropertyWriter prop = props[i];
if (prop != null) { // can have nulls in filtered list
prop.serializeAsField(bean, gen, provider);
}
}
if (_anyGetterWriter != null) {
_anyGetterWriter.getAndSerialize(bean, gen, provider);
}
} catch (Exception e) {
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
wrapAndThrow(provider, e, bean, name);
} catch (StackOverflowError e) {
/* 04-Sep-2009, tatu: Dealing with this is tricky, since we do not
* have many stack frames to spare... just one or two; can't
* make many calls.
*/
// 10-Dec-2015, tatu: and due to above, avoid "from" method, call ctor directly:
//JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e);
JsonMappingException mapE = new JsonMappingException(gen, "Infinite recursion (StackOverflowError)", e);
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
mapE.prependPath(new JsonMappingException.Reference(bean, name));
throw mapE;
}
}
/**
* Alternative serialization method that gets called when there is a
* {@link PropertyFilter} that needs to be called to determine
* which properties are to be serialized (and possibly how)
*/
protected void serializeFieldsFiltered(Object bean, JsonGenerator gen,
SerializerProvider provider)
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
throws IOException, JsonGenerationException
{
/* note: almost verbatim copy of "serializeFields"; copied (instead of merged)
* so that old method need not add check for existence of filter.
*/
final BeanPropertyWriter[] props;
if (_filteredProps != null && provider.getActiveView() != null) {
props = _filteredProps;
} else {
props = _props;
}
final PropertyFilter filter = findPropertyFilter(provider, _propertyFilterId, bean);
// better also allow missing filter actually..
if (filter == null) {
serializeFields(bean, gen, provider);
return;
}
int i = 0;
try {
for (final int len = props.length; i < len; ++i) {
BeanPropertyWriter prop = props[i];
if (prop != null) { // can have nulls in filtered list
filter.serializeAsField(bean, gen, provider, prop);
}
}
if (_anyGetterWriter != null) {
_anyGetterWriter.getAndFilter(bean, gen, provider, filter);
}
} catch (Exception e) {
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
wrapAndThrow(provider, e, bean, name);
} catch (StackOverflowError e) {
// Minimize call depth since we are close to fail:
//JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e);
JsonMappingException mapE = new JsonMappingException(gen, "Infinite recursion (StackOverflowError)", e);
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
mapE.prependPath(new JsonMappingException.Reference(bean, name));
throw mapE;
}
}
@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("object", true);
// [JACKSON-813]: Add optional JSON Schema id attribute, if found
// NOTE: not optimal, does NOT go through AnnotationIntrospector etc:
JsonSerializableSchema ann = _handledType.getAnnotation(JsonSerializableSchema.class);
if (
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>ann != null) {
String id = ann.id();
if (id != null && id.length() > 0) {
o.put("id", id);
}
}
//todo: should the classname go in the title?
//o.put("title", _className);
ObjectNode propertiesNode = o.objectNode();
final PropertyFilter filter;
if (_propertyFilterId != null) {
filter = findPropertyFilter(provider, _propertyFilterId, null);
} else {
filter = null;
}
for (int i = 0; i < _props.length; i++) {
BeanPropertyWriter prop = _props[i];
if (filter == null) {
prop.depositSchemaProperty(propertiesNode, provider);
} else {
filter.depositSchemaProperty(prop, propertiesNode, provider);
}
}
o.set("properties", propertiesNode);
return o;
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
//deposit your output format
if (visitor == null) {
return;
}
JsonObjectFormatVisitor objectVisitor = visitor.expectObjectFormat(typeHint);
if (objectVisitor == null) {
return;
}
final SerializerProvider provider = visitor.getProvider();
if (_propertyFilterId != null) {
PropertyFilter filter = findPropertyFilter(visitor.getProvider(),
_propertyFilterId, null);
for (int i = 0, end = _props.length; i < end; ++i) {
filter.depositSchemaProperty(_props[i], objectVisitor, provider);
}
} else {
Class<?> view = ((_filteredProps == null) || (provider == null))
? null : provider.getActiveView();
final BeanPropertyWriter[] props;
if (view != null) {
props = _filteredProps;
} else {
props = _props;
}
for (int i = 0, end = props.length; i < end; ++i) {
BeanPropertyWriter prop = props[i];
if (prop != null) { // may be filtered out unconditionally
prop.depositSchemaProperty(objectVisitor, provider);
}
}
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind;
import java.io.*;
import java.util.*;
import static org.junit.Assert.*;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;
import com.fasterxml.jackson.databind.type.TypeFactory;
public abstract class BaseMapTest
extends BaseTest
{
private final static Object SINGLETON_OBJECT = new Object();
/*
/**********************************************************
/* Shared helper classes
/**********************************************************
*/
/**
* Simple wrapper around boolean types, usually to test value
* conversions or wrapping
*/
protected static class BooleanWrapper {
public Boolean b;
@JsonCreator
public BooleanWrapper(Boolean value) { b = value; }
@JsonValue public Boolean value() { return b; }
}
protected static class IntWrapper {
public int i;
public IntWrapper() { }
public IntWrapper(int value) { i = value; }
}
protected static class LongWrapper {
public long l;
public LongWrapper() { }
public LongWrapper(long value) { l = value; }
}
protected static class DoubleWrapper {
public double d;
public DoubleWrapper() { }
public DoubleWrapper(double value) { d = value; }
}
/**
* Simple wrapper around String type, usually to test value
* conversions or wrapping
*/
protected static class StringWrapper {
public String str;
public StringWrapper() { }
public StringWrapper(String value) {
str = value;
}
}
protected static class ObjectWrapper {
private final Object object;
protected ObjectWrapper(final Object object) {
this.object = object;
}
public Object getObject() { return object; }
@JsonCreator
static ObjectWrapper jsonValue(final Object object) {
return new ObjectWrapper(object);
}
}
protected static class ListWrapper<T>
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
}
protected String asJSONObjectValueString(ObjectMapper m, Object... args)
throws IOException
{
LinkedHashMap<Object,Object> map = new LinkedHashMap<Object,Object>();
for (int i = 0, len = args.length; i < len; i += 2) {
map.put(args[i], args[i+1]);
}
return m.writeValueAsString(map);
}
/*
/**********************************************************
/* Helper methods, deserialization
/**********************************************************
*/
protected <T> T readAndMapFromString(String input, Class<T> cls)
throws IOException
{
return readAndMapFromString(SHARED_MAPPER, input, cls);
}
protected <T> T readAndMapFromString(ObjectMapper m, String input, Class<T> cls) throws IOException
{
return (T) m.readValue("\""+input+"\"", cls);
}
/*
/**********************************************************
/* Helper methods, other
/**********************************************************
*/
protected TimeZone getUTCTimeZone() {
return TimeZone.getTimeZone("GMT");
}
protected byte[] utf8Bytes(String str) {
try {
return str.getBytes("UTF-8");
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
protected static String aposToQuotes(String json) {
return json.replace("'", "\"");
}
protected static String quotesToApos(String json) {
return json.replace("\"", "'");
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.CharTypes;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Value node that contains a text value.
*/
public class TextNode
extends ValueNode
{
final static TextNode EMPTY_STRING_NODE = new TextNode("");
protected final String _value;
public TextNode(String v) { _value = v; }
/**
* Factory method that should be used to construct instances.
* For some common cases, can reuse canonical instances: currently
* this is the case for empty Strings, in future possible for
* others as well. If null is passed, will return null.
*
* @return Resulting {@link TextNode} object, if <b>v</b>
* is NOT null; null if it is.
*/
public static TextNode valueOf(String v)
{
if (v == null) {
return null;
}
if (v.length() == 0) {
return EMPTY_STRING_NODE;
}
return new TextNode(v);
}
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.STRING;
}
@Override public JsonToken asToken() { return JsonToken.VALUE_STRING; }
@Override
public String textValue() {
return _value;
}
/**
* Method for accessing textual contents assuming they were
* base64 encoded; if so, they are decoded and resulting binary
* data is returned.
*/
@SuppressWarnings("resource")
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException
{
ByteArrayBuilder builder = new ByteArrayBuilder(100);
final String str = _value;
int ptr = 0;
int len = str.length();
main_loop:
while (ptr < len) {
// first, we'll skip preceding white space, if any
char ch;
do {
ch = str.charAt(ptr++);
if (ptr >= len) {
break
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> main_loop;
}
} while (ch <= ' ');
int bits = b64variant.decodeBase64Char(ch);
if (bits < 0) {
_reportInvalidBase64(b64variant, ch, 0);
}
int decodedData = bits;
// then second base64 char; can't get padding yet, nor ws
if (ptr >= len) {
_reportBase64EOF();
}
ch = str.charAt(ptr++);
bits = b64variant.decodeBase64Char(ch);
if (bits < 0) {
_reportInvalidBase64(b64variant, ch, 1);
}
decodedData = (decodedData << 6) | bits;
// third base64 char; can be padding, but not ws
if (ptr >= len) {
// but as per [JACKSON-631] can be end-of-input, iff not using padding
if (!b64variant.usesPadding()) {
// Got 12 bits, only need 8, need to shift
decodedData >>= 4;
builder.append(decodedData);
break;
}
_reportBase64EOF();
}
ch = str.charAt(ptr++);
bits = b64variant.decodeBase64Char(ch);
// First branch: can get padding (-> 1 byte)
if (bits < 0) {
if (bits != Base64Variant.BASE64_VALUE_PADDING) {
_reportInvalidBase64(b64variant, ch, 2);
}
// Ok, must get padding
if (ptr >= len) {
_reportBase64EOF();
}
ch = str.charAt(ptr++);
if (!b64variant.usesPaddingChar(ch)) {
_reportInvalidBase64(b64variant, ch, 3, "expected padding character '"+b64variant.getPaddingChar()+"'");
}
// Got 12 bits, only need 8, need to shift
decodedData >>= 4;
builder.append(decodedData);
continue;
}
// Nope, 2 or 3 bytes
decodedData = (decodedData << 6) | bits
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>;
// fourth and last base64 char; can be padding, but not ws
if (ptr >= len) {
// but as per [JACKSON-631] can be end-of-input, iff not using padding
if (!b64variant.usesPadding()) {
decodedData >>= 2;
builder.appendTwoBytes(decodedData);
break;
}
_reportBase64EOF();
}
ch = str.charAt(ptr++);
bits = b64variant.decodeBase64Char(ch);
if (bits < 0) {
if (bits != Base64Variant.BASE64_VALUE_PADDING) {
_reportInvalidBase64(b64variant, ch, 3);
}
decodedData >>= 2;
builder.appendTwoBytes(decodedData);
} else {
// otherwise, our triple is now complete
decodedData = (decodedData << 6) | bits;
builder.appendThreeBytes(decodedData);
}
}
return builder.toByteArray();
}
@Override
public byte[] binaryValue() throws IOException {
return getBinaryValue(Base64Variants.getDefaultVariant());
}
/*
/**********************************************************
/* General type coercions
/**********************************************************
*/
@Override
public String asText() {
return _value;
}
@Override
public String asText(String defaultValue) {
return (_value == null) ? defaultValue : _value;
}
// note: neither fast nor elegant, but these work for now:
@Override
public boolean asBoolean(boolean defaultValue) {
if (_value != null) {
String v = _value.trim();
if ("true".equals(v)) {
return true;
}
if ("false".equals(v)) {
return false;
}
}
return defaultValue;
}
@Override
public int asInt(int defaultValue) {
return NumberInput.parseAsInt(_value, defaultValue);
}
@Override
public long asLong(long defaultValue) {
return NumberInput.parseAsLong(_value, defaultValue);
}
@Override
public double asDouble(double defaultValue) {
return NumberInput.parseAsDouble(_value, defaultValue);
}
/*
/**********************************************************
/* Serialization
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> /**********************************************************
*/
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider) throws IOException
{
if (_value == null) {
jg.writeNull();
} else {
jg.writeString(_value);
}
}
/*
/**********************************************************
/* Overridden standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof TextNode) {
return ((TextNode) o)._value.equals(_value);
}
return false;
}
@Override
public int hashCode() { return _value.hashCode(); }
/**
* Different from other values, Strings need quoting
*/
@Override
public String toString()
{
int len = _value.length();
len = len + 2 + (len >> 4);
StringBuilder sb = new StringBuilder(len);
appendQuoted(sb, _value);
return sb.toString();
}
protected static void appendQuoted(StringBuilder sb, String content)
{
sb.append('"');
CharTypes.appendQuoted(sb, content);
sb.append('"');
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected void _reportInvalidBase64(Base64Variant b64variant, char ch, int bindex)
throws JsonParseException
{
_reportInvalidBase64(b64variant, ch, bindex, null);
}
/**
* @param bindex Relative index within base64 character unit; between 0
* and 3 (as unit has exactly 4 characters)
*/
protected void _reportInvalidBase64(Base64Variant b64variant, char ch, int bindex, String msg)
throws JsonParseException
{
String base;
if (ch <= ' ') {
base = "Illegal white space character (code 0x"+Integer.toHexString(ch)+") as character #"+(bindex+1)+" of 4-char base64 unit: can only used between units";
} else if (b64variant.usesPaddingChar(ch)) {
base = "Unexpected padding character ('"+b64variant.getPaddingChar()+"') as
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> be null
* if no annotations were found
*/
protected final Annotations _contextAnnotations;
public Std(PropertyName name, JavaType type, PropertyName wrapperName,
Annotations contextAnnotations, AnnotatedMember member,
PropertyMetadata metadata)
{
_name = name;
_type = type;
_wrapperName = wrapperName;
_metadata = metadata;
_member = member;
_contextAnnotations = contextAnnotations;
}
/**
* @since 2.6
*/
public Std(Std base, JavaType newType) {
this(base._name, newType, base._wrapperName, base._contextAnnotations, base._member, base._metadata);
}
public Std withType(JavaType type) {
return new Std(this, type);
}
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return (_member == null) ? null : _member.getAnnotation(acls);
}
@Override
public <A extends Annotation> A getContextAnnotation(Class<A> acls) {
return (_contextAnnotations == null) ? null : _contextAnnotations.get(acls);
}
@Override
@Deprecated
public JsonFormat.Value findFormatOverrides(AnnotationIntrospector intr) {
if ((_member != null) && (intr != null)) {
JsonFormat.Value v = intr.findFormat(_member);
if (v != null) {
return v;
}
}
return EMPTY_FORMAT;
}
@Override
public JsonFormat.Value findPropertyFormat(MapperConfig<?> config, Class<?> baseType) {
JsonFormat.Value v0 = config.getDefaultPropertyFormat(baseType);
AnnotationIntrospector intr = config.getAnnotationIntrospector();
if ((intr == null) || (_member == null)) {
return v0;
}
JsonFormat.Value v = intr.findFormat(_member);
if (v == null) {
return v0;
}
return v0.withOverrides(v);
}
@Override
public JsonInclude.Value findPropertyInclusion(MapperConfig<?> config, Class<?> baseType)
{
JsonInclude.Value v0 = config.getDefaultPropertyInclusion(baseType);
AnnotationIntrospector intr = config.getAnnotationIntrospector();
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> First: if we have a property, may have property-annotation overrides
if (property != null) {
AnnotatedMember m = property.getMember();
final AnnotationIntrospector intr = serializers.getAnnotationIntrospector();
if (m != null) {
Object serDef = intr.findContentSerializer(m);
if (serDef != null) {
ser = serializers.serializerInstance(m, serDef);
}
}
}
JsonFormat.Value format = findFormatOverrides(serializers, property, handledType());
if (format != null) {
unwrapSingle = format.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
}
if (ser == null) {
ser = _elementSerializer;
}
// [databind#124]: May have a content converter
ser = findConvertingContentSerializer(serializers, property, ser);
if (ser == null) {
// 30-Sep-2012, tatu: One more thing -- if explicit content type is annotated,
// we can consider it a static case as well.
if (_elementType != null) {
if (_staticTyping && !_elementType.isJavaLangObject()) {
ser = serializers.findValueSerializer(_elementType, property);
}
}
} else {
ser = serializers.handleSecondaryContextualization(ser, property);
}
return withResolved(property, vts, ser, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _elementType;
}
@Override
public JsonSerializer<?> getContentSerializer() {
return _elementSerializer;
}
@Override
public boolean isEmpty(SerializerProvider prov, Object[] value) {
return (value == null) || (value.length == 0);
}
@Override
public boolean hasSingleElement(Object[] value) {
return (value.length == 1);
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(Object[] value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
final int len = value.length;
if (len == 1) {
if (((_unwrapSingle == null) &&
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(Object[] value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
final int len = value.length;
if (len == 0) {
return;
}
if (_elementSerializer != null) {
serializeContentsUsing(value, gen, provider, _elementSerializer);
return;
}
if (_valueTypeSerializer != null) {
serializeTypedContents(value, gen, provider);
return;
}
int i = 0;
Object elem = null;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(gen);
continue;
}
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
}
serializer.serialize(elem, gen, provider);
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
/* 05-Mar-2009, tatu: But one nasty edge is when we get
* StackOverflow: usually due to infinite loop. But that gets
* hidden within an InvocationTargetException...
*/
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>, elem, i);
}
}
public void serializeContentsUsing(Object[] value, JsonGenerator jgen, SerializerProvider provider,
JsonSerializer<Object> ser) throws IOException
{
final int len = value.length;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
Object elem = null;
try {
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, elem, i);
}
}
public void serializeTypedContents(Object[] value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
final int len = value.length;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
Object elem = null;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializer.serializeWithType(elem, jgen, provider, typeSer);
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>.wrapWithPath(t, elem, i);
}
}
@SuppressWarnings("deprecation")
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("array", true);
if (typeHint != null) {
JavaType javaType = provider.constructType(typeHint);
if (javaType.isArrayType()) {
Class<?> componentType = ((ArrayType) javaType).getContentType().getRawClass();
// 15-Oct-2010, tatu: We can't serialize plain Object.class; but what should it produce here? Untyped?
if (componentType == Object.class) {
o.set("items", com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode());
} else {
JsonSerializer<Object> ser = provider.findValueSerializer(componentType, _property);
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(provider, null) :
com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
o.set("items", schemaNode);
}
}
}
return o;
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
JsonArrayFormatVisitor arrayVisitor = visitor.expectArrayFormat(typeHint);
if (arrayVisitor != null) {
TypeFactory tf = visitor.getProvider().getTypeFactory();
JavaType contentType = tf.moreSpecificType(_elementType, typeHint.getContentType());
if (contentType == null) {
throw JsonMappingException.from(visitor.getProvider(), "Could not resolve type");
}
JsonSerializer<?> valueSer = _elementSerializer;
if (valueSer == null) {
valueSer = visitor.getProvider().findValueSerializer(contentType, _property);
}
arrayVisitor.itemsFormat(valueSer, contentType);
}
}
protected final JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map,
Class<?> type, SerializerProvider provider) throws JsonMappingException
{
PropertySerializerMap.SerializerAndMapResult result = map.findAndAddSecondarySerializer(type, provider, _property);
// did we get a new map
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.node;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.util.RawValue;
/**
* This intermediate base class is used for all container nodes,
* specifically, array and object nodes.
*/
public abstract class ContainerNode<T extends ContainerNode<T>>
extends BaseJsonNode
implements JsonNodeCreator
{
/**
* We will keep a reference to the Object (usually TreeMapper)
* that can construct instances of nodes to add to this container
* node.
*/
protected final JsonNodeFactory _nodeFactory;
protected ContainerNode(JsonNodeFactory nc) {
_nodeFactory = nc;
}
// all containers are mutable: can't define:
// @Override public abstract <T extends JsonNode> T deepCopy();
@Override
public abstract JsonToken asToken();
@Override
public String asText() { return ""; }
/*
/**********************************************************
/* Methods reset as abstract to force real implementation
/**********************************************************
*/
@Override
public abstract int size();
@Override
public abstract JsonNode get(int index);
@Override
public abstract JsonNode get(String fieldName);
/*
/**********************************************************
/* JsonNodeCreator implementation, just dispatch to
/* the real creator
/**********************************************************
*/
/**
* Factory method that constructs and returns an empty {@link ArrayNode}
* Construction is done using registered {@link JsonNodeFactory}.
*/
@Override
public final ArrayNode arrayNode() { return _nodeFactory.arrayNode(); }
/**
* Factory method that constructs and returns an {@link ArrayNode} with an initial capacity
* Construction is done using registered {@link JsonNodeFactory}
* @param capacity the initial capacity of the ArrayNode
*/
@Override
public final ArrayNode arrayNode(int capacity) { return _nodeFactory.arrayNode(capacity); }
/**
* Factory method that constructs and returns an empty {@link ObjectNode}
* Construction is done using registered {@link JsonNodeFactory}.
*/
@Override
public final ObjectNode objectNode() { return _nodeFactory.objectNode(); }
@Override
public final NullNode nullNode() { return _nodeFactory.nullNode();
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> cls = t.getType();
String id = t.hasName() ? t.getName() : _defaultTypeId(cls);
if (forSer) {
typeToId.put(cls.getName(), id);
}
if (forDeser) {
// One more problem; sometimes we have same name for multiple types;
// if so, use most specific
JavaType prev = idToType.get(id);
if (prev != null) { // Can only override if more specific
if (cls.isAssignableFrom(prev.getRawClass())) { // nope, more generic (or same)
continue;
}
}
idToType.put(id, config.constructType(cls));
}
}
}
return new TypeNameIdResolver(config, baseType, typeToId, idToType);
}
@Override
public JsonTypeInfo.Id getMechanism() { return JsonTypeInfo.Id.NAME; }
@Override
public String idFromValue(Object value) {
return idFromClass(value.getClass());
}
protected String idFromClass(Class<?> clazz)
{
if (clazz == null) {
return null;
}
Class<?> cls = _typeFactory.constructType(clazz).getRawClass();
final String key = cls.getName();
String name;
synchronized (_typeToId) {
name = _typeToId.get(key);
if (name == null) {
// 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name
// can either throw an exception, or use default name...
if (_config.isAnnotationProcessingEnabled()) {
BeanDescription beanDesc = _config.introspectClassAnnotations(cls);
name = _config.getAnnotationIntrospector().findTypeName(beanDesc.getClassInfo());
}
if (name == null) {
// And if still not found, let's choose default?
name = _defaultTypeId(cls);
}
_typeToId.put(key, name);
}
}
return name;
}
@Override
public String idFromValueAndType(Object value, Class<?> type) {
/* 18-Jan-2013, tatu: We may be called with null
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> value occasionally
* it seems; nothing much we can figure out that way.
*/
if (value == null) {
return idFromClass(type);
}
return idFromValue(value);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
return _typeFromId(id);
}
protected JavaType _typeFromId(String id) {
/* Now: if no type is found, should we try to locate it by
* some other means? (specifically, if in same package as base type,
* could just try Class.forName)
* For now let's not add any such workarounds; can add if need be
*/
return _idToType.get(id);
}
@Override
public String getDescForKnownTypeIds() {
return new TreeSet<String>(_idToType.keySet()).toString();
}
@Override
public String toString() {
return String.format("[%s; id-to-type=%s]", getClass().getName(), _idToType);
}
/*
/*********************************************************
/* Helper methods
/*********************************************************
*/
/**
* If no name was explicitly given for a class, we will just
* use non-qualified class name
*/
protected static String _defaultTypeId(Class<?> cls)
{
String n = cls.getName();
int ix = n.lastIndexOf('.');
return (ix < 0) ? n : n.substring(ix+1);
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.reflect.Method;
import java.util.*;
/**
* Simple helper class used to keep track of collection of
* {@link AnnotatedMethod}s, accessible by lookup. Lookup
* is usually needed for augmenting and overriding annotations.
*/
public final class AnnotatedMethodMap
implements Iterable<AnnotatedMethod>
{
protected LinkedHashMap<MemberKey,AnnotatedMethod> _methods;
public AnnotatedMethodMap() { }
/**
* Method called to add specified annotated method in the Map.
*/
public void add(AnnotatedMethod am)
{
if (_methods == null) {
_methods = new LinkedHashMap<MemberKey,AnnotatedMethod>();
}
_methods.put(new MemberKey(am.getAnnotated()), am);
}
/**
* Method called to remove specified method, assuming
* it exists in the Map
*/
public AnnotatedMethod remove(AnnotatedMethod am)
{
return remove(am.getAnnotated());
}
public AnnotatedMethod remove(Method m)
{
if (_methods != null) {
return _methods.remove(new MemberKey(m));
}
return null;
}
public boolean isEmpty() {
return (_methods == null || _methods.size() == 0);
}
public int size() {
return (_methods == null) ? 0 : _methods.size();
}
public AnnotatedMethod find(String name, Class<?>[] paramTypes)
{
if (_methods == null) {
return null;
}
return _methods.get(new MemberKey(name, paramTypes));
}
public AnnotatedMethod find(Method m)
{
if (_methods == null) {
return null;
}
return _methods.get(new MemberKey(m));
}
/*
/**********************************************************
/* Iterable implementation (for iterating over values)
/**********************************************************
*/
@Override
public Iterator<AnnotatedMethod> iterator()
{
if (_methods != null) {
return _methods.values().iterator();
}
List<AnnotatedMethod> empty = Collections.emptyList();
return empty.iterator();
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.cfg;
import java.util.*;
/**
* Container for individual {@link ConfigOverride} values.
*
* @since 2.8
*/
public class ConfigOverrides
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected Map<Class<?>, MutableConfigOverride> _overrides;
public ConfigOverrides() {
_overrides = null;
}
protected ConfigOverrides(Map<Class<?>, MutableConfigOverride> overrides) {
_overrides = overrides;
}
public ConfigOverrides copy()
{
if (_overrides == null) {
return new ConfigOverrides();
}
Map<Class<?>, MutableConfigOverride> newOverrides = _newMap();
for (Map.Entry<Class<?>, MutableConfigOverride> entry : _overrides.entrySet()) {
newOverrides.put(entry.getKey(), entry.getValue().copy());
}
return new ConfigOverrides(newOverrides);
}
public ConfigOverride findOverride(Class<?> type) {
if (_overrides == null) {
return null;
}
return _overrides.get(type);
}
public MutableConfigOverride findOrCreateOverride(Class<?> type) {
if (_overrides == null) {
_overrides = _newMap();
}
MutableConfigOverride override = _overrides.get(type);
if (override == null) {
override = new MutableConfigOverride();
_overrides.put(type, override);
}
return override;
}
protected Map<Class<?>, MutableConfigOverride> _newMap() {
return new HashMap<Class<?>, MutableConfigOverride>();
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.databind.introspect.ObjectIdInfo;
import com.fasterxml.jackson.databind.ser.*;
public class PropertyBasedObjectIdGenerator
extends ObjectIdGenerators.PropertyGenerator
{
private static final long serialVersionUID = 1L;
protected final BeanPropertyWriter _property;
public PropertyBasedObjectIdGenerator(ObjectIdInfo oid, BeanPropertyWriter prop)
{
this(oid.getScope(), prop);
}
protected PropertyBasedObjectIdGenerator(Class<?> scope, BeanPropertyWriter prop)
{
super(scope);
_property = prop;
}
/**
* We must override this method, to prevent errors when scopes are the same,
* but underlying class (on which to access property) is different.
*/
@Override
public boolean canUseFor(ObjectIdGenerator<?> gen) {
if (gen.getClass() == getClass()) {
PropertyBasedObjectIdGenerator other = (PropertyBasedObjectIdGenerator) gen;
if (other.getScope() == _scope) {
/* 26-Jul-2012, tatu: This is actually not enough, because the property
* accessor within BeanPropertyWriter won't work for other property fields
* (see [https://github.com/FasterXML/jackson-module-jaxb-annotations/issues/9]
* for details).
* So we need to verify that underlying property is actually the same.
*/
return (other._property == _property);
}
}
return false;
}
@Override
public Object generateId(Object forPojo) {
try {
return _property.get(forPojo);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException("Problem accessing property '"
+_property.getName()+"': "+e.getMessage(), e);
}
}
@Override
public ObjectIdGenerator<Object> forScope(Class<?> scope) {
return (scope == _scope) ? this : new PropertyBasedObjectIdGenerator(scope, _property);
}
@Override
public ObjectIdGenerator<Object> newForSerialization(Object context) {
// No state
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> /**********************************************************
/* Simple accessors
/**********************************************************
*/
@Override
public JavaType getContentType() {
return VALUE_TYPE;
}
@Override
public JsonSerializer<?> getContentSerializer() {
return _elementSerializer;
}
@Override
public boolean isEmpty(SerializerProvider prov, String[] value) {
return (value == null) || (value.length == 0);
}
@Override
public boolean hasSingleElement(String[] value) {
return (value.length == 1);
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(String[] value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final int len = value.length;
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(String[] value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final int len = value.length;
if (len == 0) {
return;
}
if (_elementSerializer != null) {
serializeContentsSlow(value, gen, provider, _elementSerializer);
return;
}
for (int i = 0; i < len; ++i) {
String str = value[i];
if (str == null) {
gen.writeNull();
} else {
gen.writeString(value[i]);
}
}
}
private void serializeContentsSlow(String[] value, JsonGenerator gen, SerializerProvider provider, JsonSerializer<Object> ser)
throws IOException
{
for (int i = 0, len = value.length; i < len; ++i) {
String str = value[i];
if (str == null) {
provider.defaultSerializeNull(gen);
} else {
ser.serialize(value[i], gen, provider);
}
}
}
@Override
public JsonNode getSchema(SerializerProvider provider
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>> valueType)
throws IOException, JsonParseException, JsonMappingException
{
return (T) _readMapAndClose(_jsonFactory.createParser(src), _typeFactory.constructType(valueType));
}
@SuppressWarnings("unchecked")
public <T> T readValue(byte[] src, int offset, int len,
Class<T> valueType)
throws IOException, JsonParseException, JsonMappingException
{
return (T) _readMapAndClose(_jsonFactory.createParser(src, offset, len), _typeFactory.constructType(valueType));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T readValue(byte[] src, TypeReference valueTypeRef)
throws IOException, JsonParseException, JsonMappingException
{
return (T) _readMapAndClose(_jsonFactory.createParser(src), _typeFactory.constructType(valueTypeRef));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T readValue(byte[] src, int offset, int len,
TypeReference valueTypeRef)
throws IOException, JsonParseException, JsonMappingException
{
return (T) _readMapAndClose(_jsonFactory.createParser(src, offset, len), _typeFactory.constructType(valueTypeRef));
}
@SuppressWarnings("unchecked")
public <T> T readValue(byte[] src, JavaType valueType)
throws IOException, JsonParseException, JsonMappingException
{
return (T) _readMapAndClose(_jsonFactory.createParser(src), valueType);
}
@SuppressWarnings("unchecked")
public <T> T readValue(byte[] src, int offset, int len,
JavaType valueType)
throws IOException, JsonParseException, JsonMappingException
{
return (T) _readMapAndClose(_jsonFactory.createParser(src, offset, len), valueType);
}
@SuppressWarnings("unchecked")
public <T> T readValue(DataInput src, Class<T> valueType) throws IOException
{
return (T) _readMapAndClose(_jsonFactory.createParser(src),
_typeFactory.constructType(valueType));
}
@SuppressWarnings("unchecked")
public <T> T readValue(DataInput src, JavaType valueType) throws IOException
{
return (T
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> tatu: Should try to support namespaces etc but...
String expSimpleName = expRootName.getSimpleName();
if (p.getCurrentToken() != JsonToken.START_OBJECT) {
ctxt.reportWrongTokenException(p, JsonToken.START_OBJECT,
"Current token not START_OBJECT (needed to unwrap root name '%s'), but %s",
expSimpleName, p.getCurrentToken());
}
if (p.nextToken() != JsonToken.FIELD_NAME) {
ctxt.reportWrongTokenException(p, JsonToken.FIELD_NAME,
"Current token not FIELD_NAME (to contain expected root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
String actualName = p.getCurrentName();
if (!expSimpleName.equals(actualName)) {
ctxt.reportMappingException("Root name '%s' does not match expected ('%s') for type %s",
actualName, expSimpleName, rootType);
}
// ok, then move to value itself....
p.nextToken();
Object result = deser.deserialize(p, ctxt);
// and last, verify that we now get matching END_OBJECT
if (p.nextToken() != JsonToken.END_OBJECT) {
ctxt.reportWrongTokenException(p, JsonToken.END_OBJECT,
"Current token not END_OBJECT (to match wrapper object with root name '%s'), but %s",
expSimpleName, p.getCurrentToken());
}
return result;
}
/*
/**********************************************************
/* Internal methods, other
/**********************************************************
*/
/**
* Method called to locate deserializer for the passed root-level value.
*/
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt,
JavaType valueType)
throws JsonMappingException
{
// First: have we already seen it?
JsonDeserializer<Object> deser = _rootDeserializers.get(valueType);
if (deser != null) {
return deser;
}
// Nope: need to ask provider to resolve it
deser = ctxt.findRootValueDeserializer(valueType);
if (deser == null) { // can this happen?
throw JsonMappingException.from(ctxt,
"Can not find a deserializer for type "+valueType);
}
_rootDeserializers.put
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> public JacksonAnnotationIntrospector setConstructorPropertiesImpliesCreator(boolean b)
{
_cfgConstructorPropertiesImpliesCreator = b;
return this;
}
/*
/**********************************************************
/* General annotation properties
/**********************************************************
*/
/**
* Annotations with meta-annotation {@link JacksonAnnotationsInside}
* are considered bundles.
*/
@Override
public boolean isAnnotationBundle(Annotation ann) {
// 22-Sep-2015, tatu: Caching here has modest effect on JavaSE, and only
// mostly in degenerate cases where introspection used more often than
// it should (like recreating ObjectMapper once per read/write).
// But it may be more beneficial on platforms like Android (should verify)
Class<?> type = ann.annotationType();
Boolean b = _annotationsInside.get(type);
if (b == null) {
b = type.getAnnotation(JacksonAnnotationsInside.class) != null;
_annotationsInside.putIfAbsent(type, b);
}
return b.booleanValue();
}
/*
/**********************************************************
/* General annotations
/**********************************************************
*/
/**
* Since 2.6, we have supported use of {@link JsonProperty} for specifying
* explicit serialized name
*/
@Override
@Deprecated
public String findEnumValue(Enum<?> value)
{
// 11-Jun-2015, tatu: As per [databind#677], need to allow explicit naming.
// Unfortunately can not quite use standard AnnotatedClass here (due to various
// reasons, including odd representation JVM uses); has to do for now
try {
// We know that values are actually static fields with matching name so:
Field f = value.getClass().getField(value.name());
if (f != null) {
JsonProperty prop = f.getAnnotation(JsonProperty.class);
if (prop != null) {
String n = prop.value();
if (n != null && !n.isEmpty()) {
return n;
}
}
}
} catch (SecurityException e) {
// 17-Sep-2015, tatu: Anything we could/should do here?
} catch (NoSuchFieldException e) {
// 1
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>7-Sep-2015, tatu: should not really happen. But... can we do anything?
}
return value.name();
}
@Override // since 2.7
public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[] names) {
HashMap<String,String> expl = null;
for (Field f : ClassUtil.getDeclaredFields(enumType)) {
if (!f.isEnumConstant()) {
continue;
}
JsonProperty prop = f.getAnnotation(JsonProperty.class);
if (prop == null) {
continue;
}
String n = prop.value();
if (n.isEmpty()) {
continue;
}
if (expl == null) {
expl = new HashMap<String,String>();
}
expl.put(f.getName(), n);
}
// and then stitch them together if and as necessary
if (expl != null) {
for (int i = 0, end = enumValues.length; i < end; ++i) {
String defName = enumValues[i].name();
String explValue = expl.get(defName);
if (explValue != null) {
names[i] = explValue;
}
}
}
return names;
}
/**
* Finds the Enum value that should be considered the default value, if possible.
* <p>
* This implementation relies on {@link JsonEnumDefaultValue} annotation to determine the default value if present.
*
* @param enumCls The Enum class to scan for the default value.
* @return null if none found or it's not possible to determine one.
* @since 2.8
*/
@Override
public Enum<?> findDefaultEnumValue(Class<Enum<?>> enumCls) {
return ClassUtil.findFirstAnnotatedEnumValue(enumCls, JsonEnumDefaultValue.class);
}
/*
/**********************************************************
/* General class annotations
/**********************************************************
*/
@Override
public PropertyName findRootName(AnnotatedClass ac)
{
JsonRootName ann = _findAnnotation(ac, JsonRootName.class);
if (ann == null) {
return null;
}
String ns = ann.namespace();
if (ns != null && ns.length() == 0) {
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> JsonPropertyOrder order = _findAnnotation(ann, JsonPropertyOrder.class);
/* 23-Jun-2015, tatu: as per [databind#840], let's only consider
* `true` to have any significance.
*/
if ((order != null) && order.alphabetic()) {
return Boolean.TRUE;
}
return null;
}
@Override
public void findAndAddVirtualProperties(MapperConfig<?> config, AnnotatedClass ac,
List<BeanPropertyWriter> properties) {
JsonAppend ann = _findAnnotation(ac, JsonAppend.class);
if (ann == null) {
return;
}
final boolean prepend = ann.prepend();
JavaType propType = null;
// First: any attribute-backed properties?
JsonAppend.Attr[] attrs = ann.attrs();
for (int i = 0, len = attrs.length; i < len; ++i) {
if (propType == null) {
propType = config.constructType(Object.class);
}
BeanPropertyWriter bpw = _constructVirtualProperty(attrs[i],
config, ac, propType);
if (prepend) {
properties.add(i, bpw);
} else {
properties.add(bpw);
}
}
// Then: general-purpose virtual properties?
JsonAppend.Prop[] props = ann.props();
for (int i = 0, len = props.length; i < len; ++i) {
BeanPropertyWriter bpw = _constructVirtualProperty(props[i],
config, ac);
if (prepend) {
properties.add(i, bpw);
} else {
properties.add(bpw);
}
}
}
protected BeanPropertyWriter _constructVirtualProperty(JsonAppend.Attr attr,
MapperConfig<?> config, AnnotatedClass ac, JavaType type)
{
PropertyMetadata metadata = attr.required() ?
PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL;
// could add Index, Description in future, if those matter
String attrName = attr.value();
// allow explicit renaming; if none, default to attribute name
PropertyName propName = _propertyName(attr.propName(), attr.propNamespace());
if (!propName
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> serialization resolution for complex (usually
* container) types
*/
public void setNonTrivialBaseType(JavaType t) {
_nonTrivialBaseType = t;
}
/*
/***********************************************************
/* JDK Serializability
/***********************************************************
*/
/*
* Ideally would not require mutable state, and instead would re-create with
* final settings. However, as things are, with sub-types and all, simplest
* to just change Field/Method value directly.
*/
Object readResolve() {
if (_member instanceof AnnotatedField) {
_accessorMethod = null;
_field = (Field) _member.getMember();
} else if (_member instanceof AnnotatedMethod) {
_accessorMethod = (Method) _member.getMember();
_field = null;
}
if (_serializer == null) {
_dynamicSerializers = PropertySerializerMap.emptyForProperties();
}
return this;
}
/*
/************************************************************
/* BeanProperty impl
/***********************************************************
*/
// Note: also part of 'PropertyWriter'
@Override
public String getName() {
return _name.getValue();
}
// Note: also part of 'PropertyWriter'
@Override
public PropertyName getFullName() { // !!! TODO: impl properly
return new PropertyName(_name.getValue());
}
@Override
public JavaType getType() {
return _declaredType;
}
@Override
public PropertyName getWrapperName() {
return _wrapperName;
}
// Note: also part of 'PropertyWriter'
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return (_member == null) ? null : _member.getAnnotation(acls);
}
// Note: also part of 'PropertyWriter'
@Override
public <A extends Annotation> A getContextAnnotation(Class<A> acls) {
return (_contextAnnotations == null) ? null : _contextAnnotations
.get(acls);
}
@Override
public AnnotatedMember getMember() {
return _member;
}
// @since 2.3 -- needed so it can be overridden by unwrapping writer
protected void _depositSchemaProperty(ObjectNode propertiesNode,
JsonNode schemaNode) {
propertiesNode.set(getName(), schemaNode);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> }
/*
/***********************************************************
/* Managing and accessing of opaque internal settings
/* (used by extensions)
/***********************************************************
*/
/**
* Method for accessing value of specified internal setting.
*
* @return Value of the setting, if any; null if none.
*/
public Object getInternalSetting(Object key) {
return (_internalSettings == null) ? null : _internalSettings.get(key);
}
/**
* Method for setting specific internal setting to given value
*
* @return Old value of the setting, if any (null if none)
*/
public Object setInternalSetting(Object key, Object value) {
if (_internalSettings == null) {
_internalSettings = new HashMap<Object, Object>();
}
return _internalSettings.put(key, value);
}
/**
* Method for removing entry for specified internal setting.
*
* @return Existing value of the setting, if any (null if none)
*/
public Object removeInternalSetting(Object key) {
Object removed = null;
if (_internalSettings != null) {
removed = _internalSettings.remove(key);
// to reduce memory usage, let's also drop the Map itself, if empty
if (_internalSettings.size() == 0) {
_internalSettings = null;
}
}
return removed;
}
/*
/***********************************************************
/* Accessors
/***********************************************************
*/
public SerializableString getSerializedName() {
return _name;
}
public boolean hasSerializer() {
return _serializer != null;
}
public boolean hasNullSerializer() {
return _nullSerializer != null;
}
/**
* @since 2.6
*/
public TypeSerializer getTypeSerializer() {
return _typeSerializer;
}
/**
* Accessor that will return true if this bean property has to support
* "unwrapping"; ability to replace POJO structural wrapping with optional
* name prefix and/or suffix (or in some cases, just removal of wrapper
* name).
* <p>
* Default implementation simply returns false.
*
* @since 2.3
*/
public boolean isUnwrapping() {
return false;
}
public boolean willSuppressNulls() {
return _suppressNulls;
}
/**
* Method called to
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> check to see if this property has a name that would
* conflict with a given name.
*
* @since 2.6
*/
public boolean wouldConflictWithName(PropertyName name) {
if (_wrapperName != null) {
return _wrapperName.equals(name);
}
// Bit convoluted since our support for namespaces is spotty but:
return name.hasSimpleName(_name.getValue()) && !name.hasNamespace();
}
// Needed by BeanSerializer#getSchema
public JsonSerializer<Object> getSerializer() {
return _serializer;
}
public JavaType getSerializationType() {
return _cfgSerializationType;
}
public Class<?> getRawSerializationType() {
return (_cfgSerializationType == null) ? null : _cfgSerializationType
.getRawClass();
}
/**
* @deprecated Since 2.7, to be removed from 2.9, use {@link #getType()} instead.
*/
@Deprecated
public Class<?> getPropertyType() {
if (_accessorMethod != null) {
return _accessorMethod.getReturnType();
}
if (_field != null) {
return _field.getType();
}
return null;
}
/**
* Get the generic property type of this property writer.
*
* @return The property type, or null if not found.
*
* @deprecated Since 2.7, to be removed from 2.9, use {@link #getType()} instead.
*/
@Deprecated
public Type getGenericPropertyType() {
if (_accessorMethod != null) {
return _accessorMethod.getGenericReturnType();
}
if (_field != null) {
return _field.getGenericType();
}
return null;
}
public Class<?>[] getViews() {
return _includeInViews;
}
/*
/***********************************************************
/* PropertyWriter methods (serialization)
/***********************************************************
*/
/**
* Method called to access property that this bean stands for, from within
* given bean, and to serialize it as a JSON Object field using appropriate
* serializer.
*/
@Override
public void serializeAsField(Object bean, JsonGenerator gen,
SerializerProvider prov) throws Exception {
// inlined 'get()'
final Object value = (_accessorMethod == null) ? _field.get(bean)
:
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> SerializerProvider prov) throws Exception {
// inlined 'get()'
final Object value = (_accessorMethod == null) ? _field.get(bean)
: _accessorMethod.invoke(bean);
if (value == null) { // nulls need specialized handling
if (_nullSerializer != null) {
_nullSerializer.serialize(null, gen, prov);
} else { // can NOT suppress entries in tabular output
gen.writeNull();
}
return;
}
// otherwise find serializer to use
JsonSerializer<Object> ser = _serializer;
if (ser == null) {
Class<?> cls = value.getClass();
PropertySerializerMap map = _dynamicSerializers;
ser = map.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(map, cls, prov);
}
}
// and then see if we must suppress certain values (default, empty)
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) { // can NOT suppress entries in
// tabular output
serializeAsPlaceholder(bean, gen, prov);
return;
}
} else if (_suppressableValue.equals(value)) { // can NOT suppress
// entries in tabular
// output
serializeAsPlaceholder(bean, gen, prov);
return;
}
}
// For non-nulls: simple check for direct cycles
if (value == bean) {
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
/**
* Method called to serialize a placeholder used in tabular output when real
* value is not to be included (is filtered out), but when we need an entry
* so that field indexes will not be off. Typically this should output null
* or empty String, depending on datatype.
*
* @since 2.1
*/
@Override
public void serializeAsPlaceholder(Object bean, JsonGenerator gen,
SerializerProvider prov) throws Exception {
if (_nullSerializer != null) {
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>nonTrivialBaseType != null) {
JavaType t = provider.constructSpecializedType(_nonTrivialBaseType,
type);
result = map.findAndAddPrimarySerializer(t, provider, this);
} else {
result = map.findAndAddPrimarySerializer(type, provider, this);
}
// did we get a new map of serializers? If so, start using it
if (map != result.map) {
_dynamicSerializers = result.map;
}
return result.serializer;
}
/**
* Method that can be used to access value of the property this Object
* describes, from given bean instance.
* <p>
* Note: method is final as it should not need to be overridden -- rather,
* calling method(s) ({@link #serializeAsField}) should be overridden to
* change the behavior
*/
public final Object get(Object bean) throws Exception {
return (_accessorMethod == null) ? _field.get(bean) : _accessorMethod
.invoke(bean);
}
/**
* Method called to handle a direct self-reference through this property.
* Method can choose to indicate an error by throwing
* {@link JsonMappingException}; fully handle serialization (and return
* true); or indicate that it should be serialized normally (return false).
* <p>
* Default implementation will throw {@link JsonMappingException} if
* {@link SerializationFeature#FAIL_ON_SELF_REFERENCES} is enabled; or
* return <code>false</code> if it is disabled.
*
* @return True if method fully handled self-referential value; false if not
* (caller is to handle it) or {@link JsonMappingException} if there
* is no way handle it
*/
protected boolean _handleSelfReference(Object bean, JsonGenerator gen,
SerializerProvider prov, JsonSerializer<?> ser)
throws JsonMappingException {
if (prov.isEnabled(SerializationFeature.FAIL_ON_SELF_REFERENCES)
&& !ser.usesObjectId()) {
// 05-Feb-2013, tatu: Usually a problem, but NOT if we are handling
// object id; this may be the case for BeanSerializers at least.
// 13-Feb-2014, tatu: another possible
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.Arrays;
import java.util.UUID;
import com.fasterxml.jackson.core.Base64Variants;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
public class UUIDDeserializer extends FromStringDeserializer<UUID>
{
private static final long serialVersionUID = 1L;
final static int[] HEX_DIGITS = new int[127];
static {
Arrays.fill(HEX_DIGITS, -1);
for (int i = 0; i < 10; ++i) { HEX_DIGITS['0' + i] = i; }
for (int i = 0; i < 6; ++i) {
HEX_DIGITS['a' + i] = 10 + i;
HEX_DIGITS['A' + i] = 10 + i;
}
}
public UUIDDeserializer() { super(UUID.class); }
@Override
protected UUID _deserialize(String id, DeserializationContext ctxt) throws IOException
{
// Adapted from java-uuid-generator (https://github.com/cowtowncoder/java-uuid-generator)
// which is 5x faster than UUID.fromString(value), as oper "ManualReadPerfWithUUID"
if (id.length() != 36) {
/* 14-Sep-2013, tatu: One trick we do allow, Base64-encoding, since we know
* length it must have...
*/
if (id.length() == 24) {
byte[] stuff = Base64Variants.getDefaultVariant().decode(id);
return _fromBytes(stuff, ctxt);
}
return _badFormat(id, ctxt);
}
// verify hyphens first:
if ((id.charAt(8) != '-') || (id.charAt(13) != '-')
|| (id.charAt(18) != '-') || (id.charAt(23) != '-')) {
_badFormat(id, ctxt);
}
long l1 =
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>32), ch, 0);
ch[8] = '-';
int i = (int) msb;
_appendShort(i >>> 16, ch, 9);
ch[13] = '-';
_appendShort(i, ch, 14);
ch[18] = '-';
final long lsb = value.getLeastSignificantBits();
_appendShort((int) (lsb >>> 48), ch, 19);
ch[23] = '-';
_appendShort((int) (lsb >>> 32), ch, 24);
_appendInt((int) lsb, ch, 28);
gen.writeString(ch, 0, 36);
}
private static void _appendInt(int bits, char[] ch, int offset)
{
_appendShort(bits >> 16, ch, offset);
_appendShort(bits, ch, offset+4);
}
private static void _appendShort(int bits, char[] ch, int offset)
{
ch[offset] = HEX_CHARS[(bits >> 12) & 0xF];
ch[++offset] = HEX_CHARS[(bits >> 8) & 0xF];
ch[++offset] = HEX_CHARS[(bits >> 4) & 0xF];
ch[++offset] = HEX_CHARS[bits & 0xF];
}
private final static byte[] _asBytes(UUID uuid)
{
byte[] buffer = new byte[16];
long hi = uuid.getMostSignificantBits();
long lo = uuid.getLeastSignificantBits();
_appendInt((int) (hi >> 32), buffer, 0);
_appendInt((int) hi, buffer, 4);
_appendInt((int) (lo >> 32), buffer, 8);
_appendInt((int) lo, buffer, 12);
return buffer;
}
private final static void _appendInt(int value, byte[] buffer, int offset)
{
buffer[offset] = (byte) (value >> 24);
buffer[++offset] = (byte) (value >> 16);
buffer[++offset] = (byte) (value >> 8);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Class = objectIdInfo.getGeneratorType();
// Just one special case: Property-based generator is trickier
if (implClass == ObjectIdGenerators.PropertyGenerator.class) { // most special one, needs extra work
String propName = objectIdInfo.getPropertyName().getSimpleName();
BeanPropertyWriter idProp = null;
for (int i = 0, len = props.size() ;; ++i) {
if (i == len) {
throw new IllegalArgumentException("Invalid Object Id definition for "+beanDesc.getBeanClass().getName()
+": can not find property with name '"+propName+"'");
}
BeanPropertyWriter prop = props.get(i);
if (propName.equals(prop.getName())) {
idProp = prop;
/* Let's force it to be the first property to output
* (although it may still get rearranged etc)
*/
if (i > 0) {
props.remove(i);
props.add(0, idProp);
}
break;
}
}
JavaType idType = idProp.getType();
gen = new PropertyBasedObjectIdGenerator(objectIdInfo, idProp);
// one more thing: must ensure that ObjectIdWriter does not actually write the value:
return ObjectIdWriter.construct(idType, (PropertyName) null, gen, objectIdInfo.getAlwaysAsId());
}
// other types are simpler
JavaType type = prov.constructType(implClass);
// Could require type to be passed explicitly, but we should be able to find it too:
JavaType idType = prov.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0];
gen = prov.objectIdGeneratorInstance(beanDesc.getClassInfo(), objectIdInfo);
return ObjectIdWriter.construct(idType, objectIdInfo.getPropertyName(), gen,
objectIdInfo.getAlwaysAsId());
}
/**
* Method called to construct a filtered writer, for given view
* definitions. Default implementation constructs filter that checks
* active view type to views property is to be included in.
*/
protected BeanPropertyWriter constructFilteredBeanWriter(BeanPropertyWriter writer,
Class<?>[] inViews)
{
return FilteredBeanPropertyWriter.constructViewBased(writer, inViews);
}
protected PropertyBuilder constructPropertyBuilder(SerializationConfig config
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>-classes
* if they want to provide custom view handling. As such it is not
* considered an internal implementation detail, and will be supported
* as part of API going forward.
*/
protected void processViews(SerializationConfig config, BeanSerializerBuilder builder)
{
// whether non-annotated fields are included by default or not is configurable
List<BeanPropertyWriter> props = builder.getProperties();
boolean includeByDefault = config.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION);
final int propCount = props.size();
int viewsFound = 0;
BeanPropertyWriter[] filtered = new BeanPropertyWriter[propCount];
// Simple: view information is stored within individual writers, need to combine:
for (int i = 0; i < propCount; ++i) {
BeanPropertyWriter bpw = props.get(i);
Class<?>[] views = bpw.getViews();
if (views == null) { // no view info? include or exclude by default?
if (includeByDefault) {
filtered[i] = bpw;
}
} else {
++viewsFound;
filtered[i] = constructFilteredBeanWriter(bpw, views);
}
}
// minor optimization: if no view info, include-by-default, can leave out filtering info altogether:
if (includeByDefault && viewsFound == 0) {
return;
}
builder.setFilteredProperties(filtered);
}
/**
* Method that will apply by-type limitations (as per [JACKSON-429]);
* by default this is based on {@link com.fasterxml.jackson.annotation.JsonIgnoreType}
* annotation but can be supplied by module-provided introspectors too.
*/
protected void removeIgnorableTypes(SerializationConfig config, BeanDescription beanDesc,
List<BeanPropertyDefinition> properties)
{
AnnotationIntrospector intr = config.getAnnotationIntrospector();
HashMap<Class<?>,Boolean> ignores = new HashMap<Class<?>,Boolean>();
Iterator<BeanPropertyDefinition> it = properties.iterator();
while (it.hasNext()) {
BeanPropertyDefinition property = it.next();
AnnotatedMember accessor = property.getAccessor();
if (accessor == null) {
it.remove();
continue;
}
Class<?> type = accessor.getRaw
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Type();
Boolean result = ignores.get(type);
if (result == null) {
// 21-Apr-2016, tatu: For 2.8, can specify config overrides
ConfigOverride override = config.findConfigOverride(type);
if (override != null) {
result = override.getIsIgnoredType();
}
if (result == null) {
BeanDescription desc = config.introspectClassAnnotations(type);
AnnotatedClass ac = desc.getClassInfo();
result = intr.isIgnorableType(ac);
// default to false, non-ignorable
if (result == null) {
result = Boolean.FALSE;
}
}
ignores.put(type, result);
}
// lotsa work, and yes, it is ignorable type, so:
if (result.booleanValue()) {
it.remove();
}
}
}
/**
* Helper method that will remove all properties that do not have a mutator.
*/
protected void removeSetterlessGetters(SerializationConfig config, BeanDescription beanDesc,
List<BeanPropertyDefinition> properties)
{
Iterator<BeanPropertyDefinition> it = properties.iterator();
while (it.hasNext()) {
BeanPropertyDefinition property = it.next();
// one caveat: only remove implicit properties;
// explicitly annotated ones should remain
if (!property.couldDeserialize() && !property.isExplicitlyIncluded()) {
it.remove();
}
}
}
/**
* Helper method called to ensure that we do not have "duplicate" type ids.
* Added to resolve [databind#222]
*
* @since 2.6
*/
protected List<BeanPropertyWriter> removeOverlappingTypeIds(SerializerProvider prov,
BeanDescription beanDesc, BeanSerializerBuilder builder,
List<BeanPropertyWriter> props)
{
for (int i = 0, end = props.size(); i < end; ++i) {
BeanPropertyWriter bpw = props.get(i);
TypeSerializer td = bpw.getTypeSerializer();
if ((td == null) || (td.getTypeInclusion() != As.EXTERNAL_PROPERTY)) {
continue;
}
String n = td.getPropertyName();
PropertyName typePropName = PropertyName.construct(n
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>1073], let's try to guard against possibility
// of some environments missing `java.sql.` types
try {
// note: timestamps are very similar to java.util.Date, thus serialized as such
sers.put(java.sql.Timestamp.class, DateSerializer.instance);
// leave some of less commonly used ones as lazy, no point in proactive construction
sers.put(java.sql.Date.class, SqlDateSerializer.class);
sers.put(java.sql.Time.class, SqlTimeSerializer.class);
} catch (NoClassDefFoundError e) {
// nothing much we can do here; could log, but probably not useful for now.
}
return sers.entrySet();
}
/*
/**********************************************************
/* Serializers for atomic types
/**********************************************************
*/
public static class AtomicBooleanSerializer
extends StdScalarSerializer<AtomicBoolean>
{
public AtomicBooleanSerializer() { super(AtomicBoolean.class, false); }
@Override
public void serialize(AtomicBoolean value, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonGenerationException {
gen.writeBoolean(value.get());
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("boolean", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
visitor.expectBooleanFormat(typeHint);
}
}
public static class AtomicIntegerSerializer
extends StdScalarSerializer<AtomicInteger>
{
public AtomicIntegerSerializer() { super(AtomicInteger.class, false); }
@Override
public void serialize(AtomicInteger value, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonGenerationException {
gen.writeNumber(value.get());
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("integer", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
visitIntFormat(visitor, typeHint, JsonParser.NumberType.INT);
}
}
public static class AtomicLongSerializer
extends StdScalarSerializer<AtomicLong>
{
public AtomicLongSerializer() { super(
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>AtomicLong.class, false); }
@Override
public void serialize(AtomicLong value, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonGenerationException {
gen.writeNumber(value.get());
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("integer", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
visitIntFormat(visitor, typeHint, JsonParser.NumberType.LONG);
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>atedClass(null, cls, TypeBindings.emptyBindings(),
Collections.<JavaType>emptyList(), null, null, null, null);
}
AnnotationIntrospector intr = config.isAnnotationProcessingEnabled()
? config.getAnnotationIntrospector() : null;
return new AnnotatedClass(null, cls, TypeBindings.emptyBindings(),
Collections.<JavaType>emptyList(), intr, mir, config.getTypeFactory(), null);
}
/*
/**********************************************************
/* TypeResolutionContext implementation
/**********************************************************
*/
@Override
public JavaType resolveType(Type type) {
return _typeFactory.constructType(type, _bindings);
}
/*
/**********************************************************
/* Annotated impl
/**********************************************************
*/
@Override
public Class<?> getAnnotated() { return _class; }
@Override
public int getModifiers() { return _class.getModifiers(); }
@Override
public String getName() { return _class.getName(); }
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
return _classAnnotations().get(acls);
}
@Override
public boolean hasAnnotation(Class<?> acls) {
return _classAnnotations().has(acls);
}
@Override
public boolean hasOneOf(Class<? extends Annotation>[] annoClasses) {
return _classAnnotations().hasOneOf(annoClasses);
}
@Override
public Class<?> getRawType() {
return _class;
}
@Override
public Iterable<Annotation> annotations() {
return _classAnnotations().annotations();
}
@Override
protected AnnotationMap getAllAnnotations() {
return _classAnnotations();
}
@Override
public JavaType getType() {
return _type;
}
/*
/**********************************************************
/* Public API, generic accessors
/**********************************************************
*/
public Annotations getAnnotations() {
return _classAnnotations();
}
public boolean hasAnnotations() {
return _classAnnotations().size() > 0;
}
public AnnotatedConstructor getDefaultConstructor()
{
if (!_creatorsResolved) {
resolveCreators();
}
return _defaultConstructor;
}
public List<AnnotatedConstructor> getConstructors()
{
if (!_creatorsResolved) {
resolveCreators();
}
return _constructors;
}
public List<
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>AnnotatedMethod> getStaticMethods()
{
if (!_creatorsResolved) {
resolveCreators();
}
return _creatorMethods;
}
public Iterable<AnnotatedMethod> memberMethods()
{
if (_memberMethods == null) {
resolveMemberMethods();
}
return _memberMethods;
}
public int getMemberMethodCount()
{
if (_memberMethods == null) {
resolveMemberMethods();
}
return _memberMethods.size();
}
public AnnotatedMethod findMethod(String name, Class<?>[] paramTypes)
{
if (_memberMethods == null) {
resolveMemberMethods();
}
return _memberMethods.find(name, paramTypes);
}
public int getFieldCount() {
if (_fields == null) {
resolveFields();
}
return _fields.size();
}
public Iterable<AnnotatedField> fields()
{
if (_fields == null) {
resolveFields();
}
return _fields;
}
/*
/**********************************************************
/* Public API, main-level resolution methods
/**********************************************************
*/
private AnnotationMap _classAnnotations() {
AnnotationMap anns = _classAnnotations;
if (anns == null) {
// 06-Dec-2015, tatu: yes, double-locking, typically not a good choice.
// But for typical usage pattern here (and with JVM 7 and above) is
// a reasonable choice to avoid non-common but existing race condition
// from root name lookup style usage
// Also note that race condition stems from caching only used for loading
// where just class annotations are needed
synchronized (this) {
anns = _classAnnotations;
if (anns == null) {
anns = _resolveClassAnnotations();
_classAnnotations = anns;
}
}
}
return anns;
}
/**
* Initialization method that will recursively collect Jackson
* annotations for this class and all super classes and
* interfaces.
*/
private AnnotationMap _resolveClassAnnotations()
{
AnnotationMap ca = new AnnotationMap();
// Should skip processing if annotation processing disabled
if (_annotationIntrospector != null) {
// add mix-in annotations first (overrides)
if (_primaryMixIn != null) {
_addClassMixIns(
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>ctor.getParamCount() == 0) {
_defaultConstructor = _constructDefaultConstructor(ctor, typeContext);
} else {
if (constructors == null) {
constructors = new ArrayList<AnnotatedConstructor>(Math.max(10, declaredCtors.length));
}
constructors.add(_constructNonDefaultConstructor(ctor, typeContext));
}
}
}
}
if (constructors == null) {
_constructors = Collections.emptyList();
} else {
_constructors = constructors;
}
// and if need be, augment with mix-ins
if (_primaryMixIn != null) {
if (_defaultConstructor != null || !_constructors.isEmpty()) {
_addConstructorMixIns(_primaryMixIn);
}
}
/* And then... let's remove all constructors that are deemed
* ignorable after all annotations have been properly collapsed.
*/
// AnnotationIntrospector is null if annotations not enabled; if so, can skip:
if (_annotationIntrospector != null) {
if (_defaultConstructor != null) {
if (_annotationIntrospector.hasIgnoreMarker(_defaultConstructor)) {
_defaultConstructor = null;
}
}
if (_constructors != null) {
// count down to allow safe removal
for (int i = _constructors.size(); --i >= 0; ) {
if (_annotationIntrospector.hasIgnoreMarker(_constructors.get(i))) {
_constructors.remove(i);
}
}
}
}
List<AnnotatedMethod> creatorMethods = null;
// Then static methods which are potential factory methods
for (Method m : _findClassMethods(_class)) {
if (!Modifier.isStatic(m.getModifiers())) {
continue;
}
// all factory methods are fine:
//int argCount = m.getParameterTypes().length;
if (creatorMethods == null) {
creatorMethods = new ArrayList<AnnotatedMethod>(8);
}
creatorMethods.add(_constructCreatorMethod(m, typeContext));
}
if (creatorMethods == null) {
_creatorMethods = Collections.emptyList();
} else {
_creatorMethods = creatorMethods;
// mix-ins to mix in?
if (_primaryMixIn != null) {
_addFactoryMixIns(_primaryMix
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>In);
}
// anything to ignore at this point?
if (_annotationIntrospector != null) {
// count down to allow safe removal
for (int i = _creatorMethods.size(); --i >= 0; ) {
if (_annotationIntrospector.hasIgnoreMarker(_creatorMethods.get(i))) {
_creatorMethods.remove(i);
}
}
}
}
_creatorsResolved = true;
}
/**
* Method for resolving member method information: aggregating all non-static methods
* and combining annotations (to implement method-annotation inheritance)
*
* @param methodFilter Filter used to determine which methods to include
*/
private void resolveMemberMethods()
{
_memberMethods = new AnnotatedMethodMap();
AnnotatedMethodMap mixins = new AnnotatedMethodMap();
// first: methods from the class itself
_addMemberMethods(_class, this, _memberMethods, _primaryMixIn, mixins);
// and then augment these with annotations from super-types:
for (JavaType type : _superTypes) {
Class<?> mixin = (_mixInResolver == null) ? null : _mixInResolver.findMixInClassFor(type.getRawClass());
_addMemberMethods(type.getRawClass(),
new TypeResolutionContext.Basic(_typeFactory, type.getBindings()),
_memberMethods, mixin, mixins);
}
// Special case: mix-ins for Object.class? (to apply to ALL classes)
if (_mixInResolver != null) {
Class<?> mixin = _mixInResolver.findMixInClassFor(Object.class);
if (mixin != null) {
_addMethodMixIns(_class, _memberMethods, mixin, mixins);
}
}
/* Any unmatched mix-ins? Most likely error cases (not matching
* any method); but there is one possible real use case:
* exposing Object#hashCode (alas, Object#getClass can NOT be
* exposed)
*/
// 14-Feb-2011, tatu: AnnotationIntrospector is null if annotations not enabled; if so, can skip:
if (_annotationIntrospector != null) {
if (!mixins.isEmpty()) {
Iterator<AnnotatedMethod> it = mixins.iterator();
while (it.hasNext()) {
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
/* And then from its supertypes, if any. But note that we will
* only consider super-types up until reaching the masked
* class (if found); this because often mix-in class
* is a sub-class (for convenience reasons). And if so, we
* absolutely must NOT include super types of masked class,
* as that would inverse precedence of annotations.
*/
for (Class<?> parent : ClassUtil.findSuperClasses(mixin, toMask, false)) {
_addAnnotationsIfNotPresent(annotations, ClassUtil.findClassAnnotations(parent));
}
}
/*
/**********************************************************
/* Helper methods for populating creator (ctor, factory) information
/**********************************************************
*/
protected void _addConstructorMixIns(Class<?> mixin)
{
MemberKey[] ctorKeys = null;
int ctorCount = (_constructors == null) ? 0 : _constructors.size();
for (ClassUtil.Ctor ctor0 : ClassUtil.getConstructors(mixin)) {
Constructor<?> ctor = ctor0.getConstructor();
if (ctor.getParameterTypes().length == 0) {
if (_defaultConstructor != null) {
_addMixOvers(ctor, _defaultConstructor, false);
}
} else {
if (ctorKeys == null) {
ctorKeys = new MemberKey[ctorCount];
for (int i = 0; i < ctorCount; ++i) {
ctorKeys[i] = new MemberKey(_constructors.get(i).getAnnotated());
}
}
MemberKey key = new MemberKey(ctor);
for (int i = 0; i < ctorCount; ++i) {
if (!key.equals(ctorKeys[i])) {
continue;
}
_addMixOvers(ctor, _constructors.get(i), true);
break;
}
}
}
}
protected void _addFactoryMixIns(Class<?> mixin)
{
MemberKey[] methodKeys = null;
int methodCount = _creatorMethods.size();
for (Method m : ClassUtil.getDeclaredMethods(mixin)) {
if (!Modifier.isStatic(m.getModifiers())) {
continue;
}
if (m.getParameterTypes().length == 0) {
continue;
}
if (methodKeys
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> == null) {
methodKeys = new MemberKey[methodCount];
for (int i = 0; i < methodCount; ++i) {
methodKeys[i] = new MemberKey(_creatorMethods.get(i).getAnnotated());
}
}
MemberKey key = new MemberKey(m);
for (int i = 0; i < methodCount; ++i) {
if (!key.equals(methodKeys[i])) {
continue;
}
_addMixOvers(m, _creatorMethods.get(i), true);
break;
}
}
}
/*
/**********************************************************
/* Helper methods for populating method information
/**********************************************************
*/
protected void _addMemberMethods(Class<?> cls, TypeResolutionContext typeContext,
AnnotatedMethodMap methods,
Class<?> mixInCls, AnnotatedMethodMap mixIns)
{
// first, mixIns, since they have higher priority then class methods
if (mixInCls != null) {
_addMethodMixIns(cls, methods, mixInCls, mixIns);
}
if (cls == null) { // just so caller need not check when passing super-class
return;
}
// then methods from the class itself
for (Method m : _findClassMethods(cls)) {
if (!_isIncludableMemberMethod(m)) {
continue;
}
AnnotatedMethod old = methods.find(m);
if (old == null) {
AnnotatedMethod newM = _constructMethod(m, typeContext);
methods.add(newM);
// Ok, but is there a mix-in to connect now?
old = mixIns.remove(m);
if (old != null) {
_addMixOvers(old.getAnnotated(), newM, false);
}
} else {
/* If sub-class already has the method, we only want to augment
* annotations with entries that are not masked by sub-class.
*/
_addMixUnders(m, old);
/* 06-Jan-2010, tatu: [JACKSON-450] Except that if method we saw first is
* from an interface, and we now find a non-interface definition, we should
* use this method, but with
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> combination of annotations.
* This helps (or rather, is essential) with JAXB annotations and
* may also result in faster method calls (interface calls are slightly
* costlier than regular method calls)
*/
if (old.getDeclaringClass().isInterface() && !m.getDeclaringClass().isInterface()) {
methods.add(old.withMethod(m));
}
}
}
}
protected void _addMethodMixIns(Class<?> targetClass, AnnotatedMethodMap methods,
Class<?> mixInCls, AnnotatedMethodMap mixIns)
{
// List<Class<?>> parents = ClassUtil.findSuperClasses(mixInCls, targetClass, true);
List<Class<?>> parents = ClassUtil.findRawSuperTypes(mixInCls, targetClass, true);
for (Class<?> mixin : parents) {
for (Method m : ClassUtil.getDeclaredMethods(mixin)) {
if (!_isIncludableMemberMethod(m)) {
continue;
}
AnnotatedMethod am = methods.find(m);
/* Do we already have a method to augment (from sub-class
* that will mask this mixIn)? If so, add if visible
* without masking (no such annotation)
*/
if (am != null) {
_addMixUnders(m, am);
/* Otherwise will have precedence, but must wait
* until we find the real method (mixIn methods are
* just placeholder, can't be called)
*/
} else {
// Well, or, as per [databind#515], multi-level merge within mixins...
am = mixIns.find(m);
if (am != null) {
_addMixUnders(m, am);
} else {
// 03-Nov-2015, tatu: Mix-in method never called, should not need
// to resolve generic types, so this class is fine as context
mixIns.add(_constructMethod(m, this));
}
}
}
}
}
/*
/**********************************************************
/* Helper methods for populating field information
/**********************************************************
*/
protected Map<String,AnnotatedField> _findFields(JavaType type,
TypeResolutionContext typeContext, Map<String,AnnotatedField> fields)
{
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Field : ClassUtil.getDeclaredFields(mixin)) {
// there are some dummy things (static, synthetic); better ignore
if (!_isIncludableField(mixinField)) {
continue;
}
String name = mixinField.getName();
// anything to mask? (if not, quietly ignore)
AnnotatedField maskedField = fields.get(name);
if (maskedField != null) {
_addOrOverrideAnnotations(maskedField, mixinField.getDeclaredAnnotations());
}
}
}
}
/*
/**********************************************************
/* Helper methods, constructing value types
/**********************************************************
*/
protected AnnotatedMethod _constructMethod(Method m, TypeResolutionContext typeContext)
{
/* note: parameter annotations not used for regular (getter, setter)
* methods; only for creator methods (static factory methods)
* -- at least not yet!
*/
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedMethod(typeContext, m, _emptyAnnotationMap(), null);
}
return new AnnotatedMethod(typeContext, m, _collectRelevantAnnotations(m.getDeclaredAnnotations()), null);
}
protected AnnotatedConstructor _constructDefaultConstructor(ClassUtil.Ctor ctor,
TypeResolutionContext typeContext)
{
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedConstructor(typeContext, ctor.getConstructor(), _emptyAnnotationMap(), NO_ANNOTATION_MAPS);
}
return new AnnotatedConstructor(typeContext, ctor.getConstructor(),
_collectRelevantAnnotations(ctor.getDeclaredAnnotations()), NO_ANNOTATION_MAPS);
}
protected AnnotatedConstructor _constructNonDefaultConstructor(ClassUtil.Ctor ctor,
TypeResolutionContext typeContext)
{
final int paramCount = ctor.getParamCount();
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedConstructor(typeContext, ctor.getConstructor(),
_emptyAnnotationMap(), _emptyAnnotationMaps(paramCount));
}
/* Looks like JDK has discrepancy, whereas annotations for implicit 'this'
* (for non-static inner classes) are NOT included, but type is?
* Strange, sounds like a bug. Alas, we can't really fix that...
*/
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>length;
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedMethod(typeContext, m, _emptyAnnotationMap(), _emptyAnnotationMaps(paramCount));
}
if (paramCount == 0) { // common enough we can slightly optimize
return new AnnotatedMethod(typeContext, m, _collectRelevantAnnotations(m.getDeclaredAnnotations()),
NO_ANNOTATION_MAPS);
}
return new AnnotatedMethod(typeContext, m, _collectRelevantAnnotations(m.getDeclaredAnnotations()),
_collectRelevantAnnotations(m.getParameterAnnotations()));
}
protected AnnotatedField _constructField(Field f, TypeResolutionContext typeContext)
{
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedField(typeContext, f, _emptyAnnotationMap());
}
return new AnnotatedField(typeContext, f, _collectRelevantAnnotations(f.getDeclaredAnnotations()));
}
private AnnotationMap _emptyAnnotationMap() {
return new AnnotationMap();
}
private AnnotationMap[] _emptyAnnotationMaps(int count) {
if (count == 0) {
return NO_ANNOTATION_MAPS;
}
AnnotationMap[] maps = new AnnotationMap[count];
for (int i = 0; i < count; ++i) {
maps[i] = _emptyAnnotationMap();
}
return maps;
}
/*
/**********************************************************
/* Helper methods, inclusion filtering
/**********************************************************
*/
protected boolean _isIncludableMemberMethod(Method m)
{
if (Modifier.isStatic(m.getModifiers())) {
return false;
}
/* 07-Apr-2009, tatu: Looks like generics can introduce hidden
* bridge and/or synthetic methods. I don't think we want to
* consider those...
*/
if (m.isSynthetic() || m.isBridge()) {
return false;
}
// also, for now we have no use for methods with 2 or more arguments:
int pcount = m.getParameterTypes().length;
return (pcount <= 2);
}
private boolean _isIncludableField(Field f)
{
// Most likely synthetic fields, if any
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>, are to be skipped similar to methods
if (f.isSynthetic()) {
return false;
}
// Static fields are never included. Transient are (since 2.6), for
// purpose of propagating removal
int mods = f.getModifiers();
if (Modifier.isStatic(mods)) {
return false;
}
return true;
}
// for [databind#1005]: do not use or expose synthetic constructors
private boolean _isIncludableConstructor(Constructor<?> c)
{
return !c.isSynthetic();
}
/*
/**********************************************************
/* Helper methods, attaching annotations
/**********************************************************
*/
protected AnnotationMap[] _collectRelevantAnnotations(Annotation[][] anns)
{
int len = anns.length;
AnnotationMap[] result = new AnnotationMap[len];
for (int i = 0; i < len; ++i) {
result[i] = _collectRelevantAnnotations(anns[i]);
}
return result;
}
protected AnnotationMap _collectRelevantAnnotations(Annotation[] anns)
{
return _addAnnotationsIfNotPresent(new AnnotationMap(), anns);
}
/* Helper method used to add all applicable annotations from given set.
* Takes into account possible "annotation bundles" (meta-annotations to
* include instead of main-level annotation)
*/
private AnnotationMap _addAnnotationsIfNotPresent(AnnotationMap result, Annotation[] anns)
{
if (anns != null) {
List<Annotation> fromBundles = null;
for (Annotation ann : anns) { // first: direct annotations
// note: we will NOT filter out non-Jackson anns any more
boolean wasNotPresent = result.addIfNotPresent(ann);
if (wasNotPresent && _isAnnotationBundle(ann)) {
fromBundles = _addFromBundle(ann, fromBundles);
}
}
if (fromBundles != null) { // and secondarily handle bundles, if any found: precedence important
_addAnnotationsIfNotPresent(result, fromBundles.toArray(new Annotation[fromBundles.size()]));
}
}
return result;
}
private List<Annotation> _addFromBundle(Annotation bundle, List<Annotation> result)
{
for (Annotation
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> a : ClassUtil.findClassAnnotations(bundle.annotationType())) {
// minor optimization: by-pass 2 common JDK meta-annotations
if ((a instanceof Target) || (a instanceof Retention)) {
continue;
}
if (result == null) {
result = new ArrayList<Annotation>();
}
result.add(a);
}
return result;
}
private void _addAnnotationsIfNotPresent(AnnotatedMember target, Annotation[] anns)
{
if (anns != null) {
List<Annotation> fromBundles = null;
for (Annotation ann : anns) { // first: direct annotations
boolean wasNotPresent = target.addIfNotPresent(ann);
if (wasNotPresent && _isAnnotationBundle(ann)) {
fromBundles = _addFromBundle(ann, fromBundles);
}
}
if (fromBundles != null) { // and secondarily handle bundles, if any found: precedence important
_addAnnotationsIfNotPresent(target, fromBundles.toArray(new Annotation[fromBundles.size()]));
}
}
}
private void _addOrOverrideAnnotations(AnnotatedMember target, Annotation[] anns)
{
if (anns != null) {
List<Annotation> fromBundles = null;
for (Annotation ann : anns) { // first: direct annotations
boolean wasModified = target.addOrOverride(ann);
if (wasModified && _isAnnotationBundle(ann)) {
fromBundles = _addFromBundle(ann, fromBundles);
}
}
if (fromBundles != null) { // and then bundles, if any: important for precedence
_addOrOverrideAnnotations(target, fromBundles.toArray(new Annotation[fromBundles.size()]));
}
}
}
/**
* @param addParamAnnotations Whether parameter annotations are to be
* added as well
*/
protected void _addMixOvers(Constructor<?> mixin, AnnotatedConstructor target,
boolean addParamAnnotations)
{
_addOrOverrideAnnotations(target, mixin.getDeclaredAnnotations());
if (addParamAnnotations) {
Annotation[][] pa = mixin.getParameterAnnotations();
for (int i = 0, len = pa.length; i < len; ++i) {
for (Annotation a : pa[i])
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> {
target.addOrOverrideParam(i, a);
}
}
}
}
/**
* @param addParamAnnotations Whether parameter annotations are to be
* added as well
*/
protected void _addMixOvers(Method mixin, AnnotatedMethod target,
boolean addParamAnnotations)
{
_addOrOverrideAnnotations(target, mixin.getDeclaredAnnotations());
if (addParamAnnotations) {
Annotation[][] pa = mixin.getParameterAnnotations();
for (int i = 0, len = pa.length; i < len; ++i) {
for (Annotation a : pa[i]) {
target.addOrOverrideParam(i, a);
}
}
}
}
/**
* Method that will add annotations from specified source method to target method,
* but only if target does not yet have them.
*/
protected void _addMixUnders(Method src, AnnotatedMethod target) {
_addAnnotationsIfNotPresent(target, src.getDeclaredAnnotations());
}
private final boolean _isAnnotationBundle(Annotation ann) {
return (_annotationIntrospector != null) && _annotationIntrospector.isAnnotationBundle(ann);
}
/**
* Helper method that gets methods declared in given class; usually a simple thing,
* but sometimes (as per [databind#785]) more complicated, depending on classloader
* setup.
*
* @since 2.4.7
*/
protected Method[] _findClassMethods(Class<?> cls)
{
try {
return ClassUtil.getDeclaredMethods(cls);
} catch (final NoClassDefFoundError ex) {
// One of the methods had a class that was not found in the cls.getClassLoader.
// Maybe the developer was nice and has a different class loader for this context.
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null){
// Nope... this is going to end poorly
throw ex;
}
final Class<?> contextClass;
try {
contextClass = loader.loadClass(cls.getName());
} catch (ClassNotFoundException e) {
// !!! TODO: 08-May-2015, tatu: Chain appropriately once we have JDK 1.7/Java7 as baseline
//ex.addSuppressed(e); Not until Jack
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Ignored) {
return true;
}
}
return false;
}
/**
* Method called to find out set of explicit names for accessors
* bound together due to implicit name.
*
* @since 2.4
*/
public Set<PropertyName> findExplicitNames()
{
Set<PropertyName> renamed = null;
renamed = _findExplicitNames(_fields, renamed);
renamed = _findExplicitNames(_getters, renamed);
renamed = _findExplicitNames(_setters, renamed);
renamed = _findExplicitNames(_ctorParameters, renamed);
if (renamed == null) {
return Collections.emptySet();
}
return renamed;
}
/**
* Method called when a previous call to {@link #findExplicitNames} found
* multiple distinct explicit names, and the property this builder represents
* basically needs to be broken apart and replaced by a set of more than
* one properties.
*
* @since 2.4
*/
public Collection<POJOPropertyBuilder> explode(Collection<PropertyName> newNames)
{
HashMap<PropertyName,POJOPropertyBuilder> props = new HashMap<PropertyName,POJOPropertyBuilder>();
_explode(newNames, props, _fields);
_explode(newNames, props, _getters);
_explode(newNames, props, _setters);
_explode(newNames, props, _ctorParameters);
return props.values();
}
@SuppressWarnings("unchecked")
private void _explode(Collection<PropertyName> newNames,
Map<PropertyName,POJOPropertyBuilder> props,
Linked<?> accessors)
{
final Linked<?> firstAcc = accessors; // clumsy, part 1
for (Linked<?> node = accessors; node != null; node = node.next) {
PropertyName name = node.name;
if (!node.isNameExplicit || name == null) { // no explicit name -- problem!
// [databind#541] ... but only as long as it's visible
if (!node.isVisible) {
continue;
}
throw new IllegalStateException("Conflicting/ambiguous property name definitions (implicit name '"
+_name+"'): found multiple explicit names: "
+newNames+", but also implicit accessor: "+node);
}
POJOPropertyBuilder prop = props.get(name);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.util.Set;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Variant of {@link BeanDeserializer} used for handling deserialization
* of POJOs when serialized as JSON Arrays, instead of JSON Objects.
*
* @since 2.1
*/
public class BeanAsArrayDeserializer
extends BeanDeserializerBase
{
private static final long serialVersionUID = 1L;
/**
* Deserializer we delegate operations that we can not handle.
*/
protected final BeanDeserializerBase _delegate;
/**
* Properties in order expected to be found in JSON array.
*/
protected final SettableBeanProperty[] _orderedProperties;
/*
/**********************************************************
/* Life-cycle, construction, initialization
/**********************************************************
*/
/**
* Main constructor used both for creating new instances (by
* {@link BeanDeserializer#asArrayDeserializer}) and for
* creating copies with different delegate.
*/
public BeanAsArrayDeserializer(BeanDeserializerBase delegate,
SettableBeanProperty[] ordered)
{
super(delegate);
_delegate = delegate;
_orderedProperties = ordered;
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* We can't do much about this; could either replace _delegate
* with unwrapping instance, or just replace this one. Latter seems
* more sensible.
*/
return _delegate.unwrappingDeserializer(unwrapper);
}
@Override
public BeanDeserializerBase withObjectIdReader(ObjectIdReader oir) {
return new BeanAsArrayDeserializer(_delegate.withObjectIdReader(oir),
_orderedProperties);
}
@Override
public BeanDeserializerBase withIgnorableProperties(Set<String> ignorableProps) {
return new BeanAsArrayDeserializer(_delegate.withIgnorableProperties(ignorableProps),
_orderedProperties);
}
@Override
public BeanDeserializerBase withBeanProperties(BeanPropertyMap props) {
return new BeanAsArrayDeserializer(_delegate
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>.withBeanProperties(props),
_orderedProperties);
}
@Override
protected BeanDeserializerBase asArrayDeserializer() {
return this;
}
/*
/**********************************************************
/* JsonDeserializer implementation
/**********************************************************
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// Let's delegate just in case we got a JSON Object (could error out, alternatively?)
if (!p.isExpectedStartArrayToken()) {
return _deserializeFromNonArray(p, ctxt);
}
if (!_vanillaProcessing) {
return _deserializeNonVanilla(p, ctxt);
}
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
final SettableBeanProperty[] props = _orderedProperties;
int i = 0;
final int propCount = props.length;
while (true) {
if (p.nextToken() == JsonToken.END_ARRAY) {
return bean;
}
if (i == propCount) {
break;
}
SettableBeanProperty prop = props[i];
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, prop.getName(), ctxt);
}
} else { // just skip?
p.skipChildren();
}
++i;
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
ctxt.reportWrongTokenException(p, JsonToken.END_ARRAY,
"Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
// never gets here
}
// otherwise, skip until end
do {
p.skipChildren();
} while (p.nextToken() != JsonToken.END_ARRAY);
return bean;
}
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt, Object bean)
throws IOException
{
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
/* No good way to verify that we
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> have an array... although could I guess
* check via JsonParser. So let's assume everything is working fine, for now.
*/
if (_injectables != null) {
injectValues(ctxt, bean);
}
final SettableBeanProperty[] props = _orderedProperties;
int i = 0;
final int propCount = props.length;
while (true) {
if (p.nextToken() == JsonToken.END_ARRAY) {
return bean;
}
if (i == propCount) {
break;
}
SettableBeanProperty prop = props[i];
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, prop.getName(), ctxt);
}
} else { // just skip?
p.skipChildren();
}
++i;
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
ctxt.reportWrongTokenException(p, JsonToken.END_ARRAY,
"Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
// never gets here
}
// otherwise, skip until end
do {
p.skipChildren();
} while (p.nextToken() != JsonToken.END_ARRAY);
return bean;
}
// needed since 2.1
@Override
public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt)
throws IOException
{
return _deserializeFromNonArray(p, ctxt);
}
/*
/**********************************************************
/* Helper methods, non-standard creation
/**********************************************************
*/
/**
* Alternate deserialization method that has to check many more configuration
* aspects than the "vanilla" processing.
*/
protected Object _deserializeNonVanilla(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_nonStandardCreation) {
return deserializeFromObjectUsingNonDefault(p, ctxt);
}
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
if (_injectables != null) {
injectValues
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>(ctxt, bean);
}
Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
final SettableBeanProperty[] props = _orderedProperties;
int i = 0;
final int propCount = props.length;
while (true) {
if (p.nextToken() == JsonToken.END_ARRAY) {
return bean;
}
if (i == propCount) {
break;
}
SettableBeanProperty prop = props[i];
++i;
if (prop != null) { // normal case
if (activeView == null || prop.visibleInView(activeView)) {
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, prop.getName(), ctxt);
}
continue;
}
}
// otherwise, skip it (view-filtered, no prop etc)
p.skipChildren();
}
// Ok; extra fields? Let's fail, unless ignoring extra props is fine
if (!_ignoreAllUnknown) {
ctxt.reportWrongTokenException(p, JsonToken.END_ARRAY,
"Unexpected JSON values; expected at most %d properties (in JSON Array)",
propCount);
// will never reach here as exception has been thrown
}
// otherwise, skip until end
do {
p.skipChildren();
} while (p.nextToken() != JsonToken.END_ARRAY);
return bean;
}
/**
* Method called to deserialize bean using "property-based creator":
* this means that a non-default constructor or factory method is
* called, and then possibly other setters. The trick is that
* values for creator method need to be buffered, first; and
* due to non-guaranteed ordering possibly some other properties
* as well.
*/
@Override
protected final Object _deserializeUsingPropertyBased(final JsonParser p, final DeserializationContext ctxt)
throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
final SettableBeanProperty[] props = _orderedProperties;
final int propCount = props.length;
int i = 0;
Object bean = null;
for (; p.
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>nextToken() != JsonToken.END_ARRAY; ++i) {
SettableBeanProperty prop = (i < propCount) ? props[i] : null;
if (prop == null) { // we get null if there are extra elements; maybe otherwise too?
p.skipChildren();
continue;
}
// if we have already constructed POJO, things are simple:
if (bean != null) {
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, prop.getName(), ctxt);
}
continue;
}
final String propName = prop.getName();
// if not yet, maybe we got a creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) {
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue; // never gets here
}
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
/* 23-Jul-2012, tatu: Not sure if these could ever be properly
* supported (since ordering of elements may not be guaranteed);
* but make explicitly non-supported for now.
*/
ctxt.reportMappingException("Can not support implicit polymorphic deserialization for POJOs-as-Arrays style: "
+"nominal type %s, actual type %s",
_beanType.getRawClass().getName(), bean.getClass().getName());
}
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
buffer.bufferProperty(prop, prop.deserialize(p, ctxt));
}
// In case we didn't quite get all the creator properties, we may have to do this:
if (bean == null) {
try {
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
/**
* Object that is used to collect arguments for non-default creator
* (non-default-constructor, or argument-taking factory method)
* before creator can be called.
* Since ordering of JSON properties is not guaranteed, this may
* require buffering of values other than ones being passed to
* creator.
*/
public final class PropertyBasedCreator
{
protected final ValueInstantiator _valueInstantiator;
/**
* Map that contains property objects for either constructor or factory
* method (whichever one is null: one property for each
* parameter for that one), keyed by logical property name
*/
protected final HashMap<String, SettableBeanProperty> _propertyLookup;
/**
* Number of properties: usually same as size of {@link #_propertyLookup},
* but not necessarily, when we have unnamed injectable properties.
*/
protected final int _propertyCount;
/**
* Array that contains properties that expect value to inject, if any;
* null if no injectable values are expected.
*/
protected final SettableBeanProperty[] _allProperties;
/*
/**********************************************************
/* Construction, initialization
/**********************************************************
*/
protected PropertyBasedCreator(ValueInstantiator valueInstantiator,
SettableBeanProperty[] creatorProps)
{
_valueInstantiator = valueInstantiator;
_propertyLookup = new HashMap<String, SettableBeanProperty>();
final int len = creatorProps.length;
_propertyCount = len;
_allProperties = new SettableBeanProperty[len];
for (int i = 0; i < len; ++i) {
SettableBeanProperty prop = creatorProps[i];
_allProperties[i] = prop;
_propertyLookup.put(prop.getName(), prop);
}
}
/**
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> * Factory method used for building actual instances: resolves deserializers
* and checks for "null values".
*/
public static PropertyBasedCreator construct(DeserializationContext ctxt,
ValueInstantiator valueInstantiator, SettableBeanProperty[] srcProps)
throws JsonMappingException
{
final int len = srcProps.length;
SettableBeanProperty[] creatorProps = new SettableBeanProperty[len];
for (int i = 0; i < len; ++i) {
SettableBeanProperty prop = srcProps[i];
if (!prop.hasValueDeserializer()) {
prop = prop.withValueDeserializer(ctxt.findContextualValueDeserializer(prop.getType(), prop));
}
creatorProps[i] = prop;
}
return new PropertyBasedCreator(valueInstantiator, creatorProps);
}
// 05-May-2015, tatu: Does not seem to be used, commented out in 2.6
/*
public void assignDeserializer(SettableBeanProperty prop, JsonDeserializer<Object> deser) {
prop = prop.withValueDeserializer(deser);
_properties.put(prop.getName(), prop);
}
*/
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
public Collection<SettableBeanProperty> properties() {
return _propertyLookup.values();
}
public SettableBeanProperty findCreatorProperty(String name) {
return _propertyLookup.get(name);
}
public SettableBeanProperty findCreatorProperty(int propertyIndex) {
for (SettableBeanProperty prop : _propertyLookup.values()) {
if (prop.getPropertyIndex() == propertyIndex) {
return prop;
}
}
return null;
}
/*
/**********************************************************
/* Building process
/**********************************************************
*/
/**
* Method called when starting to build a bean instance.
*
* @since 2.1 (added ObjectIdReader parameter -- existed in previous versions without)
*/
public PropertyValueBuffer startBuilding(JsonParser p, DeserializationContext ctxt,
ObjectIdReader oir) {
return new PropertyValueBuffer(p, ctxt, _propertyCount, oir);
}
public Object build(DeserializationContext ctxt, PropertyValueBuffer buffer) throws IOException
{
Object bean = _valueInstantiator.createFromObjectWith(ctxt,
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.ContainerSerializer;
import com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase;
/**
* This is an optimized serializer for Lists that can be efficiently
* traversed by index (as opposed to others, such as {@link LinkedList}
* that can not}.
*/
@JacksonStdImpl
public final class IndexedListSerializer
extends AsArraySerializerBase<List<?>>
{
private static final long serialVersionUID = 1L;
public IndexedListSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts,
JsonSerializer<Object> valueSerializer)
{
super(List.class, elemType, staticTyping, vts, valueSerializer);
}
public IndexedListSerializer(IndexedListSerializer src,
BeanProperty property, TypeSerializer vts, JsonSerializer<?> valueSerializer,
Boolean unwrapSingle) {
super(src, property, vts, valueSerializer, unwrapSingle);
}
@Override
public IndexedListSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new IndexedListSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider prov, List<?> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(List<?> value) {
return (value.size() == 1);
}
@Override
public ContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts) {
return new IndexedListSerializer(this,
_property, vts, _elementSerializer, _unwrapSingle);
}
@Override
public final void serialize(List<?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final int len = value.size();
if (len ==
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(List<?> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException
{
if (_elementSerializer != null) {
serializeContentsUsing(value, jgen, provider, _elementSerializer);
return;
}
if (_valueTypeSerializer != null) {
serializeTypedContents(value, jgen, provider);
return;
}
final int len = value.size();
if (len == 0) {
return;
}
int i = 0;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
Object elem = value.get(i);
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicSerializers;
}
serializer.serialize(elem, jgen, provider);
}
}
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
public void serializeContentsUsing(List<?> value, JsonGenerator jgen, SerializerProvider provider,
JsonSerializer<Object> ser)
throws IOException
{
final int len = value.size();
if (len == 0) {
return;
}
final TypeSerializer typeSer = _valueTypeSerializer;
for (int i = 0; i < len; ++i) {
Object elem = value.get(i);
try {
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> if (elem == null) {
provider.defaultSerializeNull(jgen);
} else if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
wrapAndThrow(provider, e, value, i);
}
}
}
public void serializeTypedContents(List<?> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException
{
final int len = value.size();
if (len == 0) {
return;
}
int i = 0;
try {
final TypeSerializer typeSer = _valueTypeSerializer;
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
Object elem = value.get(i);
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicSerializers;
}
serializer.serializeWithType(elem, jgen, provider, typeSer);
}
}
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
wrapAndThrow(provider, e, value, i);
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.util.*;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* Simple helper class used to keep track of collection of
* Jackson Annotations associated with annotatable things
* (methods, constructors, classes).
* Note that only Jackson-owned annotations are tracked (for now?).
*/
public final class AnnotationMap implements Annotations
{
protected HashMap<Class<?>,Annotation> _annotations;
public AnnotationMap() { }
private AnnotationMap(HashMap<Class<?>,Annotation> a) {
_annotations = a;
}
@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> A get(Class<A> cls)
{
if (_annotations == null) {
return null;
}
return (A) _annotations.get(cls);
}
public boolean has(Class<?> cls)
{
if (_annotations == null) {
return false;
}
return _annotations.containsKey(cls);
}
/**
* Helper method that can be used for a "bulk" check to see if at least
* one of given annotation types is included within this map.
*
* @since 2.7
*/
public boolean hasOneOf(Class<? extends Annotation>[] annoClasses) {
if (_annotations != null) {
for (int i = 0, end = annoClasses.length; i < end; ++i) {
if (_annotations.containsKey(annoClasses[i])) {
return true;
}
}
}
return false;
}
/**
* @since 2.3
*/
public Iterable<Annotation> annotations() {
if (_annotations == null || _annotations.size() == 0) {
return Collections.emptyList();
}
return _annotations.values();
}
public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary)
{
if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) {
return secondary;
}
if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) {
return primary;
}
HashMap<Class<?>,Annotation> annotations = new HashMap<Class<?>,Annotation>();
// add secondary ones first
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> this should be enough:
return typeDeserializer.deserializeTypedFromArray(p, ctxt);
}
/**
* Helper method called when current token is no START_ARRAY. Will either
* throw an exception, or try to handle value as if member of implicit
* array, depending on configuration.
*/
@SuppressWarnings("unchecked")
protected final Collection<Object> handleNonArray(JsonParser p, DeserializationContext ctxt,
Collection<Object> result)
throws IOException
{
// Implicit arrays from single values?
boolean canWrap = (_unwrapSingle == Boolean.TRUE) ||
((_unwrapSingle == null) &&
ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
if (!canWrap) {
return (Collection<Object>) ctxt.handleUnexpectedToken(_collectionType.getRawClass(), p);
}
JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
JsonToken t = p.getCurrentToken();
Object value;
try {
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(p, ctxt);
} else {
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
}
} catch (Exception e) {
// note: pass Object.class, not Object[].class, as we need element type for error info
throw JsonMappingException.wrapWithPath(e, Object.class, result.size());
}
result.add(value);
return result;
}
public final static class CollectionReferringAccumulator {
private final Class<?> _elementType;
private final Collection<Object> _result;
/**
* A list of {@link CollectionReferring} to maintain ordering.
*/
private List<CollectionReferring> _accumulator = new ArrayList<CollectionReferring>();
public CollectionReferringAccumulator(Class<?> elementType, Collection<Object> result) {
_elementType = elementType;
_result = result;
}
public void add(Object value)
{
if (_accumulator.isEmpty()) {
_result.add(value);
} else {
CollectionReferring ref = _accumulator.get(_accumulator.size() - 1);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Helper class used for storing mapping from property name to
* {@link SettableBeanProperty} instances.
*<p>
* Note that this class is used instead of generic {@link java.util.HashMap}
* for bit of performance gain (and some memory savings): although default
* implementation is very good for generic use cases, it can be streamlined
* a bit for specific use case we have. Even relatively small improvements
* matter since this is directly on the critical path during deserialization,
* as it is done for each and every POJO property deserialized.
*/
public class BeanPropertyMap
implements Iterable<SettableBeanProperty>,
java.io.Serializable
{
private static final long serialVersionUID = 2L;
/**
* @since 2.5
*/
protected final boolean _caseInsensitive;
private int _hashMask;
/**
* Number of entries stored in the hash area.
*/
private int _size;
private int _spillCount;
/**
* Hash area that contains key/property pairs in adjacent elements.
*/
private Object[] _hashArea;
/**
* Array of properties in the exact order they were handed in. This is
* used by as-array serialization, deserialization.
*/
private SettableBeanProperty[] _propsInOrder;
public BeanPropertyMap(boolean caseInsensitive, Collection<SettableBeanProperty> props)
{
_caseInsensitive = caseInsensitive;
_propsInOrder = props.toArray(new SettableBeanProperty[props.size()]);
init(props);
}
/**
* @since 2
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>.8
*/
protected BeanPropertyMap(BeanPropertyMap base, boolean caseInsensitive)
{
_caseInsensitive = caseInsensitive;
// 16-May-2016, tatu: Alas, not enough to just change flag, need to re-init
// as well.
_propsInOrder = Arrays.copyOf(base._propsInOrder, base._propsInOrder.length);
init(Arrays.asList(_propsInOrder));
}
/**
* Mutant factory method that constructs a new instance if desired case-insensitivity
* state differs from the state of this instance; if states are the same, returns
* <code>this</code>.
*
* @since 2.8
*/
public BeanPropertyMap withCaseInsensitivity(boolean state) {
if (_caseInsensitive == state) {
return this;
}
return new BeanPropertyMap(this, state);
}
protected void init(Collection<SettableBeanProperty> props)
{
_size = props.size();
// First: calculate size of primary hash area
final int hashSize = findSize(_size);
_hashMask = hashSize-1;
// and allocate enough to contain primary/secondary, expand for spillovers as need be
int alloc = (hashSize + (hashSize>>1)) * 2;
Object[] hashed = new Object[alloc];
int spillCount = 0;
for (SettableBeanProperty prop : props) {
// Due to removal, renaming, theoretically possible we'll have "holes" so:
if (prop == null) {
continue;
}
String key = getPropertyName(prop);
int slot = _hashCode(key);
int ix = (slot<<1);
// primary slot not free?
if (hashed[ix] != null) {
// secondary?
ix = (hashSize + (slot >> 1)) << 1;
if (hashed[ix] != null) {
// ok, spill over.
ix = ((hashSize + (hashSize >> 1) ) << 1) + spillCount;
spillCount += 2;
if (ix >= hashed.length) {
hashed = Arrays.copyOf(hashed, hashed.length + 4);
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> }
}
//System.err.println(" add '"+key+" at #"+(ix>>1)+"/"+size+" (hashed at "+slot+")");
hashed[ix] = key;
hashed[ix+1] = prop;
}
/*
for (int i = 0; i < hashed.length; i += 2) {
System.err.printf("#%02d: %s\n", i>>1, (hashed[i] == null) ? "-" : hashed[i]);
}
*/
_hashArea = hashed;
_spillCount = spillCount;
}
private final static int findSize(int size)
{
if (size <= 5) {
return 8;
}
if (size <= 12) {
return 16;
}
int needed = size + (size >> 2); // at most 80% full
int result = 32;
while (result < needed) {
result += result;
}
return result;
}
/**
* @since 2.6
*/
public static BeanPropertyMap construct(Collection<SettableBeanProperty> props, boolean caseInsensitive) {
return new BeanPropertyMap(caseInsensitive, props);
}
/**
* Fluent copy method that creates a new instance that is a copy
* of this instance except for one additional property that is
* passed as the argument.
* Note that method does not modify this instance but constructs
* and returns a new one.
*/
public BeanPropertyMap withProperty(SettableBeanProperty newProp)
{
// First: may be able to just replace?
String key = getPropertyName(newProp);
for (int i = 1, end = _hashArea.length; i < end; i += 2) {
SettableBeanProperty prop = (SettableBeanProperty) _hashArea[i];
if ((prop != null) && prop.getName().equals(key)) {
_hashArea[i] = newProp;
_propsInOrder[_findFromOrdered(prop)] = newProp;
return this;
}
}
// If not, append
final int slot = _hashCode(key);
final int hashSize = _hashMask+1;
int ix =
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> (slot<<1);
// primary slot not free?
if (_hashArea[ix] != null) {
// secondary?
ix = (hashSize + (slot >> 1)) << 1;
if (_hashArea[ix] != null) {
// ok, spill over.
ix = ((hashSize + (hashSize >> 1) ) << 1) + _spillCount;
_spillCount += 2;
if (ix >= _hashArea.length) {
_hashArea = Arrays.copyOf(_hashArea, _hashArea.length + 4);
// Uncomment for debugging only
/*
for (int i = 0; i < _hashArea.length; i += 2) {
if (_hashArea[i] != null) {
System.err.println("Property #"+(i/2)+" '"+_hashArea[i]+"'...");
}
}
System.err.println("And new propr #"+slot+" '"+key+"'");
*/
}
}
}
_hashArea[ix] = key;
_hashArea[ix+1] = newProp;
int last = _propsInOrder.length;
_propsInOrder = Arrays.copyOf(_propsInOrder, last+1);
_propsInOrder[last] = newProp;
// should we just create a new one? Or is resetting ok?
return this;
}
public BeanPropertyMap assignIndexes()
{
// order is arbitrary, but stable:
int index = 0;
for (int i = 1, end = _hashArea.length; i < end; i += 2) {
SettableBeanProperty prop = (SettableBeanProperty) _hashArea[i];
if (prop != null) {
prop.assignIndex(index++);
}
}
return this;
}
/**
* Mutant factory method for constructing a map where all entries use given
* prefix
*/
public BeanPropertyMap renameAll(NameTransformer transformer)
{
if (transformer == null || (transformer == NameTransformer.NOP)) {
return this;
}
// Try to retain insertion ordering as well
final int len = _propsInOrder.length;
ArrayList<SettableBeanProperty> newProps = new ArrayList<
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>SettableBeanProperty>(len);
for (int i = 0; i < len; ++i) {
SettableBeanProperty prop = _propsInOrder[i];
// What to do with holes? For now, retain
if (prop == null) {
newProps.add(prop);
continue;
}
newProps.add(_rename(prop, transformer));
}
// should we try to re-index? Ordering probably changed but caller probably doesn't want changes...
return new BeanPropertyMap(_caseInsensitive, newProps);
}
/**
* Mutant factory method that will use this instance as the base, and
* construct an instance that is otherwise same except for excluding
* properties with specified names.
*
* @since 2.8
*/
public BeanPropertyMap withoutProperties(Collection<String> toExclude)
{
if (toExclude.isEmpty()) {
return this;
}
final int len = _propsInOrder.length;
ArrayList<SettableBeanProperty> newProps = new ArrayList<SettableBeanProperty>(len);
for (int i = 0; i < len; ++i) {
SettableBeanProperty prop = _propsInOrder[i];
// 01-May-2015, tatu: Not 100% sure if existing `null`s should be retained;
// or, if entries to ignore should be retained as nulls. For now just
// prune them out
if (prop != null) { // may contain holes, too, check.
if (!toExclude.contains(prop.getName())) {
newProps.add(prop);
}
}
}
// should we try to re-index? Apparently no need
return new BeanPropertyMap(_caseInsensitive, newProps);
}
/**
* Specialized method that can be used to replace an existing entry
* (note: entry MUST exist; otherwise exception is thrown) with
* specified replacement.
*/
public void replace(SettableBeanProperty newProp)
{
String key = getPropertyName(newProp);
int ix = _findIndexInHash(key);
if (ix >= 0) {
SettableBeanProperty prop = (SettableBeanProperty) _hashArea[ix];
_hashArea[ix] =
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> newProp;
// also, replace in in-order
_propsInOrder[_findFromOrdered(prop)] = newProp;
return;
}
throw new NoSuchElementException("No entry '"+key+"' found, can't replace");
}
private List<SettableBeanProperty> properties() {
ArrayList<SettableBeanProperty> p = new ArrayList<SettableBeanProperty>(_size);
for (int i = 1, end = _hashArea.length; i < end; i += 2) {
SettableBeanProperty prop = (SettableBeanProperty) _hashArea[i];
if (prop != null) {
p.add(prop);
}
}
return p;
}
/**
* Accessor for traversing over all contained properties.
*/
@Override
public Iterator<SettableBeanProperty> iterator() {
return properties().iterator();
}
/**
* Method that will re-create initial insertion-ordering of
* properties contained in this map. Note that if properties
* have been removed, array may contain nulls; otherwise
* it should be consecutive.
*
* @since 2.1
*/
public SettableBeanProperty[] getPropertiesInInsertionOrder() {
return _propsInOrder;
}
// Confining this case insensitivity to this function (and the find method) in case we want to
// apply a particular locale to the lower case function. For now, using the default.
protected final String getPropertyName(SettableBeanProperty prop) {
return _caseInsensitive ? prop.getName().toLowerCase() : prop.getName();
}
/**
* @since 2.3
*/
public SettableBeanProperty find(int index)
{
// note: will scan the whole area, including primary, secondary and
// possible spill-area
for (int i = 1, end = _hashArea.length; i < end; i += 2) {
SettableBeanProperty prop = (SettableBeanProperty) _hashArea[i];
if ((prop != null) && (index == prop.getPropertyIndex())) {
return prop;
}
}
return null;
}
public SettableBeanProperty find(String key)
{
if (key == null) {
throw new IllegalArgumentException("Can not pass null
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> property name");
}
if (_caseInsensitive) {
key = key.toLowerCase();
}
// inlined `_hashCode(key)`
int slot = key.hashCode() & _hashMask;
// int h = key.hashCode();
// int slot = (h + (h >> 13)) & _hashMask;
int ix = (slot<<1);
Object match = _hashArea[ix];
if ((match == key) || key.equals(match)) {
return (SettableBeanProperty) _hashArea[ix+1];
}
return _find2(key, slot, match);
}
private final SettableBeanProperty _find2(String key, int slot, Object match)
{
if (match == null) {
return null;
}
// no? secondary?
int hashSize = _hashMask+1;
int ix = hashSize + (slot>>1) << 1;
match = _hashArea[ix];
if (key.equals(match)) {
return (SettableBeanProperty) _hashArea[ix+1];
}
if (match != null) { // _findFromSpill(...)
int i = (hashSize + (hashSize>>1)) << 1;
for (int end = i + _spillCount; i < end; i += 2) {
match = _hashArea[i];
if ((match == key) || key.equals(match)) {
return (SettableBeanProperty) _hashArea[i+1];
}
}
}
return null;
}
/*
/**********************************************************
/* Public API
/**********************************************************
*/
public int size() { return _size; }
/**
* Specialized method for removing specified existing entry.
* NOTE: entry MUST exist, otherwise an exception is thrown.
*/
public void remove(SettableBeanProperty propToRm) {
ArrayList<SettableBeanProperty> props = new ArrayList<SettableBeanProperty>(_size);
String key = getPropertyName(propToRm);
boolean found = false;
for (int i = 1, end = _hashArea.length; i < end; i += 2) {
SettableBeanProperty prop = (SettableBeanProperty) _hashArea[i];
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> if (prop == null) {
continue;
}
if (!found) {
found = key.equals(prop.getName());
if (found) {
// need to leave a hole here
_propsInOrder[_findFromOrdered(prop)] = null;
continue;
}
}
props.add(prop);
}
if (!found) {
throw new NoSuchElementException("No entry '"+propToRm.getName()+"' found, can't remove");
}
init(props);
}
/**
* Convenience method that tries to find property with given name, and
* if it is found, call {@link SettableBeanProperty#deserializeAndSet}
* on it, and return true; or, if not found, return false.
* Note, too, that if deserialization is attempted, possible exceptions
* are wrapped if and as necessary, so caller need not handle those.
*
* @since 2.5
*/
public boolean findDeserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object bean, String key) throws IOException
{
final SettableBeanProperty prop = find(key);
if (prop == null) {
return false;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, key, ctxt);
}
return true;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("Properties=[");
int count = 0;
Iterator<SettableBeanProperty> it = iterator();
while (it.hasNext()) {
SettableBeanProperty prop = it.next();
if (count++ > 0) {
sb.append(", ");
}
sb.append(prop.getName());
sb.append('(');
sb.append(prop.getType());
sb.append(')');
}
sb.append(']');
return sb.toString();
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected SettableBeanProperty _rename(SettableBeanProperty prop, NameTransformer xf)
{
if (prop == null) {
return prop;
}
String newName = xf.transform(prop.getName());
prop = prop.withSimpleName(newName);
Json
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Deserializer<?> deser = prop.getValueDeserializer();
if (deser != null) {
@SuppressWarnings("unchecked")
JsonDeserializer<Object> newDeser = (JsonDeserializer<Object>)
deser.unwrappingDeserializer(xf);
if (newDeser != deser) {
prop = prop.withValueDeserializer(newDeser);
}
}
return prop;
}
protected void wrapAndThrow(Throwable t, Object bean, String fieldName, DeserializationContext ctxt)
throws IOException
{
// inlined 'throwOrReturnThrowable'
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
// StackOverflowErrors are tricky ones; need to be careful...
boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
// Ditto for IOExceptions; except we may want to wrap JSON exceptions
if (t instanceof IOException) {
if (!wrap || !(t instanceof JsonProcessingException)) {
throw (IOException) t;
}
} else if (!wrap) { // allow disabling wrapping for unchecked exceptions
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
}
throw JsonMappingException.wrapWithPath(t, bean, fieldName);
}
/**
* Helper method used to find exact location of a property with name
* given exactly, not subject to case changes, within hash area.
* Expectation is that such property SHOULD exist, although no
* exception is thrown.
*
* @since 2.7
*/
private final int _findIndexInHash(String key)
{
final int slot = _hashCode(key);
int ix = (slot<<1);
// primary match?
if (key.equals(_hashArea[ix])) {
return ix+1;
}
// no? secondary?
int hashSize = _hashMask+1;
ix = hashSize + (slot>>1) << 1;
if (key.equals(_hashArea[ix])) {
return ix+1;
}
// perhaps spill then
int i = (hashSize + (hashSize>>1)) << 1;
for (int end
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> = i + _spillCount; i < end; i += 2) {
if (key.equals(_hashArea[i])) {
return i+1;
}
}
return -1;
}
private final int _findFromOrdered(SettableBeanProperty prop) {
for (int i = 0, end = _propsInOrder.length; i < end; ++i) {
if (_propsInOrder[i] == prop) {
return i;
}
}
throw new IllegalStateException("Illegal state: property '"+prop.getName()+"' missing from _propsInOrder");
}
// Offlined version for convenience if we want to change hashing scheme
private final int _hashCode(String key) {
// This method produces better hash, fewer collisions... yet for some
// reason produces slightly worse performance. Very strange.
// 05-Aug-2015, tatu: ... still true?
/*
int h = key.hashCode();
return (h + (h >> 13)) & _hashMask;
*/
return key.hashCode() & _hashMask;
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> = ctxt.getConfig();
VisibilityChecker<?> vchecker = config.getDefaultVisibilityChecker();
vchecker = intr.findAutoDetectVisibility(beanDesc.getClassInfo(), vchecker);
/* 24-Sep-2014, tatu: Tricky part first; need to merge resolved property information
* (which has creator parameters sprinkled around) with actual creator
* declarations (which are needed to access creator annotation, amongst other things).
* Easiest to combine that info first, then pass it to remaining processing.
*/
/* 15-Mar-2015, tatu: Alas, this won't help with constructors that only have implicit
* names. Those will need to be resolved later on.
*/
Map<AnnotatedWithParams,BeanPropertyDefinition[]> creatorDefs = _findCreatorsFromProperties(ctxt,
beanDesc);
/* Important: first add factory methods; then constructors, so
* latter can override former!
*/
_addDeserializerFactoryMethods(ctxt, beanDesc, vchecker, intr, creators, creatorDefs);
// constructors only usable on concrete types:
if (beanDesc.getType().isConcrete()) {
_addDeserializerConstructors(ctxt, beanDesc, vchecker, intr, creators, creatorDefs);
}
return creators.constructValueInstantiator(config);
}
protected Map<AnnotatedWithParams,BeanPropertyDefinition[]> _findCreatorsFromProperties(DeserializationContext ctxt,
BeanDescription beanDesc) throws JsonMappingException
{
Map<AnnotatedWithParams,BeanPropertyDefinition[]> result = Collections.emptyMap();
for (BeanPropertyDefinition propDef : beanDesc.findProperties()) {
Iterator<AnnotatedParameter> it = propDef.getConstructorParameters();
while (it.hasNext()) {
AnnotatedParameter param = it.next();
AnnotatedWithParams owner = param.getOwner();
BeanPropertyDefinition[] defs = result.get(owner);
final int index = param.getIndex();
if (defs == null) {
if (result.isEmpty()) { // since emptyMap is immutable need to create a 'real' one
result = new LinkedHashMap<AnnotatedWithParams,BeanPropertyDefinition[]>();
}
defs = new BeanPropertyDefinition[owner.getParameterCount()];
result.put(owner, defs);
} else {
if (defs[
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> may need to keep track for [#725]
List<AnnotatedConstructor> implicitCtors = null;
for (AnnotatedConstructor ctor : beanDesc.getConstructors()) {
final boolean isCreator = intr.hasCreatorAnnotation(ctor);
BeanPropertyDefinition[] propDefs = creatorParams.get(ctor);
final int argCount = ctor.getParameterCount();
// some single-arg factory methods (String, number) are auto-detected
if (argCount == 1) {
BeanPropertyDefinition argDef = (propDefs == null) ? null : propDefs[0];
boolean useProps = _checkIfCreatorPropertyBased(intr, ctor, argDef);
if (useProps) {
SettableBeanProperty[] properties = new SettableBeanProperty[1];
PropertyName name = (argDef == null) ? null : argDef.getFullName();
AnnotatedParameter arg = ctor.getParameter(0);
properties[0] = constructCreatorProperty(ctxt, beanDesc, name, 0, arg,
intr.findInjectableValueId(arg));
creators.addPropertyCreator(ctor, isCreator, properties);
} else {
/*boolean added = */ _handleSingleArgumentConstructor(ctxt, beanDesc, vchecker, intr, creators,
ctor, isCreator,
vchecker.isCreatorVisible(ctor));
// one more thing: sever link to creator property, to avoid possible later
// problems with "unresolved" constructor property
if (argDef != null) {
((POJOPropertyBuilder) argDef).removeConstructors();
}
}
// regardless, fully handled
continue;
}
// 2 or more args; all params must have names or be injectable
// 14-Mar-2015, tatu (2.6): Or, as per [#725], implicit names will also
// do, with some constraints. But that will require bit post processing...
AnnotatedParameter nonAnnotatedParam = null;
SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
int explicitNameCount = 0;
int implicitWithCreatorCount = 0;
int injectCount = 0;
for (int i = 0; i < argCount; ++i) {
final AnnotatedParameter param = ctor.getParameter(i);
Bean
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>PropertyDefinition propDef = (propDefs == null) ? null : propDefs[i];
Object injectId = intr.findInjectableValueId(param);
final PropertyName name = (propDef == null) ? null : propDef.getFullName();
if (propDef != null && propDef.isExplicitlyNamed()) {
++explicitNameCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
if (injectId != null) {
++injectCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
NameTransformer unwrapper = intr.findUnwrappingNameTransformer(param);
if (unwrapper != null) {
properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null);
++explicitNameCount;
continue;
}
// One more thing: implicit names are ok iff ctor has creator annotation
if (isCreator && (name != null && !name.isEmpty())) {
++implicitWithCreatorCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
if (nonAnnotatedParam == null) {
nonAnnotatedParam = param;
}
}
final int namedCount = explicitNameCount + implicitWithCreatorCount;
// Ok: if named or injectable, we have more work to do
if (isCreator || (explicitNameCount > 0) || (injectCount > 0)) {
// simple case; everything covered:
if ((namedCount + injectCount) == argCount) {
creators.addPropertyCreator(ctor, isCreator, properties);
continue;
}
if ((explicitNameCount == 0) && ((injectCount + 1) == argCount)) {
// Secondary: all but one injectable, one un-annotated (un-named)
creators.addDelegatingCreator(ctor, isCreator, properties);
continue;
}
// otherwise, epic fail?
// 16-Mar-2015, tatu: due to [#725], need to be more permissive. For now let's
//
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>getParameterCount();
SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
for (int i = 0; i < argCount; ++i) {
final AnnotatedParameter param = ctor.getParameter(i);
final PropertyName name = _findParamName(param, intr);
// must have name (implicit fine)
if (name == null || name.isEmpty()) {
continue main_loop;
}
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, param.getIndex(),
param, /*injectId*/ null);
}
if (found != null) { // only one allowed
found = null;
break;
}
found = ctor;
foundProps = properties;
}
// found one and only one visible? Ship it!
if (found != null) {
creators.addPropertyCreator(found, /*isCreator*/ false, foundProps);
BasicBeanDescription bbd = (BasicBeanDescription) beanDesc;
// Also: add properties, to keep error messages complete wrt known properties...
for (SettableBeanProperty prop : foundProps) {
PropertyName pn = prop.getFullName();
if (!bbd.hasProperty(pn)) {
BeanPropertyDefinition newDef = SimpleBeanPropertyDefinition.construct(
ctxt.getConfig(), prop.getMember(), pn);
bbd.addProperty(newDef);
}
}
}
}
protected boolean _checkIfCreatorPropertyBased(AnnotationIntrospector intr,
AnnotatedWithParams creator, BeanPropertyDefinition propDef)
{
JsonCreator.Mode mode = intr.findCreatorBinding(creator);
if (mode == JsonCreator.Mode.PROPERTIES) {
return true;
}
if (mode == JsonCreator.Mode.DELEGATING) {
return false;
}
// If explicit name, or inject id, property-based
if (((propDef != null) && propDef.isExplicitlyNamed())
|| (intr.findInjectableValueId(creator.getParameter(0)) != null)) {
return true;
}
if (propDef != null) {
// One more thing: if implicit name matches property with a getter
// or field, we'll consider it property-based as well
String implName = propDef.getName();
if (implName != null && !implName.
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> final int argCount = factory.getParameterCount();
// zero-arg methods must be annotated; if so, are "default creators" [JACKSON-850]
if (argCount == 0) {
if (isCreator) {
creators.setDefaultCreator(factory);
}
continue;
}
final BeanPropertyDefinition[] propDefs = creatorParams.get(factory);
// some single-arg factory methods (String, number) are auto-detected
if (argCount == 1) {
BeanPropertyDefinition argDef = (propDefs == null) ? null : propDefs[0];
boolean useProps = _checkIfCreatorPropertyBased(intr, factory, argDef);
if (!useProps) { // not property based but delegating
/*boolean added=*/ _handleSingleArgumentFactory(config, beanDesc, vchecker, intr, creators,
factory, isCreator);
// otherwise just ignored
continue;
}
// fall through if there's name
} else {
// more than 2 args, must have @JsonCreator
if (!isCreator) {
continue;
}
}
// 1 or more args; all params must have name annotations
AnnotatedParameter nonAnnotatedParam = null;
SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
int implicitNameCount = 0;
int explicitNameCount = 0;
int injectCount = 0;
for (int i = 0; i < argCount; ++i) {
final AnnotatedParameter param = factory.getParameter(i);
BeanPropertyDefinition propDef = (propDefs == null) ? null : propDefs[i];
Object injectId = intr.findInjectableValueId(param);
final PropertyName name = (propDef == null) ? null : propDef.getFullName();
if (propDef != null && propDef.isExplicitlyNamed()) {
++explicitNameCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
if (injectId != null) {
++injectCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
NameTransformer unwrapper = intr.findUnwrappingNameTransformer
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>(param);
if (unwrapper != null) {
properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null);
++implicitNameCount;
continue;
}
// One more thing: implicit names are ok iff ctor has creator annotation
if (isCreator) {
if (name != null && !name.isEmpty()) {
++implicitNameCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
}
/* 25-Sep-2014, tatu: Actually, we may end up "losing" naming due to higher-priority constructor
* (see TestCreators#testConstructorCreator() test). And just to avoid running into that problem,
* let's add one more work around
*/
/*
PropertyName name2 = _findExplicitParamName(param, intr);
if (name2 != null && !name2.isEmpty()) {
// Hmmh. Ok, fine. So what are we to do with it... ?
// For now... skip. May need to revisit this, should this become problematic
continue main_loop;
}
*/
if (nonAnnotatedParam == null) {
nonAnnotatedParam = param;
}
}
final int namedCount = explicitNameCount + implicitNameCount;
// Ok: if named or injectable, we have more work to do
if (isCreator || explicitNameCount > 0 || injectCount > 0) {
// simple case; everything covered:
if ((namedCount + injectCount) == argCount) {
creators.addPropertyCreator(factory, isCreator, properties);
} else if ((explicitNameCount == 0) && ((injectCount + 1) == argCount)) {
// [712] secondary: all but one injectable, one un-annotated (un-named)
creators.addDelegatingCreator(factory, isCreator, properties);
} else { // otherwise, epic fail
throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex()
+" of factory method "+factory+" has no property name annotation; must have name when multiple-parameter constructor annotated as Creator");
}
}
}
}
protected boolean _handleSingle
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> interface we'd
* be implementing)
*/
if (deser == null) {
if (type.isInterface() || type.isAbstract()) {
CollectionType implType = _mapAbstractCollectionType(type, config);
if (implType == null) {
// [databind#292]: Actually, may be fine, but only if polymorphich deser enabled
if (type.getTypeHandler() == null) {
throw new IllegalArgumentException("Can not find a deserializer for non-concrete Collection type "+type);
}
deser = AbstractDeserializer.constructForNonPOJO(beanDesc);
} else {
type = implType;
// But if so, also need to re-check creators...
beanDesc = config.introspectForCreation(type);
}
}
if (deser == null) {
ValueInstantiator inst = findValueInstantiator(ctxt, beanDesc);
if (!inst.canCreateUsingDefault()) {
// [databind#161]: No default constructor for ArrayBlockingQueue...
if (type.getRawClass() == ArrayBlockingQueue.class) {
return new ArrayBlockingQueueDeserializer(type, contentDeser, contentTypeDeser, inst);
}
}
// Can use more optimal deserializer if content type is String, so:
if (contentType.getRawClass() == String.class) {
// no value type deserializer because Strings are one of natural/native types:
deser = new StringCollectionDeserializer(type, contentDeser, inst);
} else {
deser = new CollectionDeserializer(type, contentDeser, contentTypeDeser, inst);
}
}
}
// allow post-processing it too
if (_factoryConfig.hasDeserializerModifiers()) {
for (BeanDeserializerModifier mod : _factoryConfig.deserializerModifiers()) {
deser = mod.modifyCollectionDeserializer(config, type, beanDesc, deser);
}
}
return deser;
}
protected CollectionType _mapAbstractCollectionType(JavaType type, DeserializationConfig config)
{
Class<?> collectionClass = type.getRawClass();
collectionClass = _collectionFallbacks.get(collectionClass.getName());
if (collectionClass == null) {
return null;
}
return (CollectionType) config.constructSpecializedType(type, collectionClass);
}
// Copied almost ver
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> == null) {
contentTypeDeser = findTypeDeserializer(config, contentType);
}
// 23-Nov-2010, tatu: Custom deserializer?
JsonDeserializer<?> deser = _findCustomMapDeserializer(type, config, beanDesc,
keyDes, contentTypeDeser, contentDeser);
if (deser == null) {
// Value handling is identical for all, but EnumMap requires special handling for keys
Class<?> mapClass = type.getRawClass();
if (EnumMap.class.isAssignableFrom(mapClass)) {
Class<?> kt = keyType.getRawClass();
if (kt == null || !kt.isEnum()) {
throw new IllegalArgumentException("Can not construct EnumMap; generic (key) type not available");
}
deser = new EnumMapDeserializer(type, null, contentDeser, contentTypeDeser);
}
// Otherwise, generic handler works ok.
/* But there is one more twist: if we are being asked to instantiate
* an interface or abstract Map, we need to either find something
* that implements the thing, or give up.
*
* Note that we do NOT try to guess based on secondary interfaces
* here; that would probably not work correctly since casts would
* fail later on (as the primary type is not the interface we'd
* be implementing)
*/
if (deser == null) {
if (type.isInterface() || type.isAbstract()) {
@SuppressWarnings("rawtypes")
Class<? extends Map> fallback = _mapFallbacks.get(mapClass.getName());
if (fallback != null) {
mapClass = fallback;
type = (MapType) config.constructSpecializedType(type, mapClass);
// But if so, also need to re-check creators...
beanDesc = config.introspectForCreation(type);
} else {
// [databind#292]: Actually, may be fine, but only if polymorphic deser enabled
if (type.getTypeHandler() == null) {
throw new IllegalArgumentException("Can not find a deserializer for non-concrete Map type "+type);
}
deser = AbstractDeserializer.constructForNonPOJO(beanDesc);
}
}
if (deser == null) {
ValueInstantiator inst = findValueInstantiator(ctxt, beanDesc);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>unknownType();
}
JavaType vt = type.containedType(1);
if (vt == null) {
vt = TypeFactory.unknownType();
}
TypeDeserializer vts = (TypeDeserializer) vt.getTypeHandler();
if (vts == null) {
vts = findTypeDeserializer(ctxt.getConfig(), vt);
}
JsonDeserializer<Object> valueDeser = vt.getValueHandler();
KeyDeserializer keyDes = (KeyDeserializer) kt.getValueHandler();
return new MapEntryDeserializer(type, keyDes, valueDeser, vts);
}
String clsName = rawType.getName();
if (rawType.isPrimitive() || clsName.startsWith("java.")) {
// Primitives/wrappers, other Numbers:
JsonDeserializer<?> deser = NumberDeserializers.find(rawType, clsName);
if (deser == null) {
deser = DateDeserializers.find(rawType, clsName);
}
if (deser != null) {
return deser;
}
}
// and a few Jackson types as well:
if (rawType == TokenBuffer.class) {
return new TokenBufferDeserializer();
}
JsonDeserializer<?> deser = findOptionalStdDeserializer(ctxt, type, beanDesc);
if (deser != null) {
return deser;
}
return JdkDeserializers.find(rawType, clsName);
}
protected JavaType _findRemappedType(DeserializationConfig config, Class<?> rawType) throws JsonMappingException {
JavaType type = mapAbstractType(config, config.constructType(rawType));
return (type == null || type.hasRawClass(rawType)) ? null : type;
}
/*
/**********************************************************
/* Helper methods, finding custom deserializers
/**********************************************************
*/
protected JsonDeserializer<?> _findCustomTreeNodeDeserializer(Class<? extends JsonNode> type,
DeserializationConfig config, BeanDescription beanDesc)
throws JsonMappingException
{
for (Deserializers d : _factoryConfig.deserializers()) {
JsonDeserializer<?> deser = d.findTreeNodeDeserializer(type, config, beanDesc);
if (deser != null) {
return deser;
}
}
return null;
}
protected JsonDeserializer<?> _findCustomReferenceDeserializer(ReferenceType type,
DeserializationConfig config
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>);
return result;
}
@Override
public Object[] deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException
{
/* Should there be separate handling for base64 stuff?
* for now this should be enough:
*/
return (Object[]) typeDeserializer.deserializeTypedFromArray(p, ctxt);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected Byte[] deserializeFromBase64(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// First same as what PrimitiveArrayDeserializers.ByteDeser does:
byte[] b = p.getBinaryValue(ctxt.getBase64Variant());
// But then need to convert to wrappers
Byte[] result = new Byte[b.length];
for (int i = 0, len = b.length; i < len; ++i) {
result[i] = Byte.valueOf(b[i]);
}
return result;
}
protected Object[] handleNonArray(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// Empty String can become null...
if (p.hasToken(JsonToken.VALUE_STRING)
&& ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
String str = p.getText();
if (str.length() == 0) {
return null;
}
}
// Can we do implicit coercion to a single-element array still?
boolean canWrap = (_unwrapSingle == Boolean.TRUE) ||
((_unwrapSingle == null) &&
ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
if (!canWrap) {
// One exception; byte arrays are generally serialized as base64, so that should be handled
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING
// note: not `byte[]`, but `Byte[]` -- former is primitive array
&& _elementClass == Byte.class) {
return deserializeFromBase64(p, ctxt);
}
return (Object[]) ctxt.handleUnexpectedToken(_arrayType.getRawClass(), p);
}
JsonToken t = p.getCurrentToken();
Object value;
if (t == JsonToken.VALUE_
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Override
public CollectionSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new CollectionSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider prov, Collection<?> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(Collection<?> value) {
Iterator<?> it = value.iterator();
if (!it.hasNext()) {
return false;
}
it.next();
return !it.hasNext();
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(Collection<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, jgen, provider);
return;
}
}
jgen.writeStartArray(len);
serializeContents(value, jgen, provider);
jgen.writeEndArray();
}
@Override
public void serializeContents(Collection<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
if (_elementSerializer != null) {
serializeContentsUsing(value, jgen, provider, _elementSerializer);
return;
}
Iterator<?> it = value.iterator();
if (!it.hasNext()) {
return;
}
PropertySerializerMap serializers = _dynamicSerializers;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
try {
do {
Object elem = it.next();
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicSerializers;
}
if (typeSer == null) {
serializer.serialize(elem, jgen, provider);
} else {
serializer.serializeWithType(elem, jgen, provider, typeSer);
}
}
++i;
} while (it.hasNext());
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
public void serializeContentsUsing(Collection<?> value, JsonGenerator jgen, SerializerProvider provider,
JsonSerializer<Object> ser)
throws IOException, JsonGenerationException
{
Iterator<?> it = value.iterator();
if (it.hasNext()) {
TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
do {
Object elem = it.next();
try {
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
}
++i;
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
} while (it.hasNext());
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.type;
import java.util.ArrayList;
import com.fasterxml.jackson.databind.JavaType;
/**
* Simple helper class used to keep track of 'call stack' for classes being referenced
* (as well as unbound variables)
*
* @since 2.7
*/
public final class ClassStack
{
protected final ClassStack _parent;
protected final Class<?> _current;
private ArrayList<ResolvedRecursiveType> _selfRefs;
public ClassStack(Class<?> rootType) {
this(null, rootType);
}
private ClassStack(ClassStack parent, Class<?> curr) {
_parent = parent;
_current = curr;
}
/**
* @return New stack frame, if addition is ok; null if not
*/
public ClassStack child(Class<?> cls) {
return new ClassStack(this, cls);
}
/**
* Method called to indicate that there is a self-reference from
* deeper down in stack pointing into type this stack frame represents.
*/
public void addSelfReference(ResolvedRecursiveType ref)
{
if (_selfRefs == null) {
_selfRefs = new ArrayList<ResolvedRecursiveType>();
}
_selfRefs.add(ref);
}
/**
* Method called when type that this stack frame represents is
* fully resolved, allowing self-references to be completed
* (if there are any)
*/
public void resolveSelfReferences(JavaType resolved)
{
if (_selfRefs != null) {
for (ResolvedRecursiveType ref : _selfRefs) {
ref.setReference(resolved);
}
}
}
public ClassStack find(Class<?> cls)
{
if (_current == cls) return this;
for (ClassStack curr = _parent; curr != null; curr = curr._parent) {
if (curr._current == cls) {
return curr;
}
}
return null;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[ClassStack (self-refs: ")
.append((_selfRefs == null) ? "0" : String.valueOf(_selfRefs.size()))
.append(')')
;
for (ClassStack curr = this; curr != null; curr =
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
@SuppressWarnings("serial")
public class EnumSetSerializer
extends AsArraySerializerBase<EnumSet<? extends Enum<?>>>
{
/**
* @since 2.6
*/
public EnumSetSerializer(JavaType elemType) {
super(EnumSet.class, elemType, true, null, null);
}
/**
* @deprecated since 2.6
*/
@Deprecated // since 2.6
public EnumSetSerializer(JavaType elemType, BeanProperty property) {
this(elemType);
}
public EnumSetSerializer(EnumSetSerializer src,
BeanProperty property, TypeSerializer vts, JsonSerializer<?> valueSerializer,
Boolean unwrapSingle) {
super(src, property, vts, valueSerializer, unwrapSingle);
}
@Override
public EnumSetSerializer _withValueTypeSerializer(TypeSerializer vts) {
// no typing for enums (always "hard" type)
return this;
}
@Override
public EnumSetSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new EnumSetSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
@Override
public boolean isEmpty(SerializerProvider prov, EnumSet<? extends Enum<?>> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(EnumSet<? extends Enum<?>> value) {
return value.size() == 1;
}
@Override
public final void serialize(EnumSet<? extends Enum<?>> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null)
&& provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.deser;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.impl.*;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
import com.fasterxml.jackson.databind.util.NameTransformer;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Deserializer class that can deserialize instances of
* arbitrary bean objects, usually from JSON Object structs,
*/
public class BeanDeserializer
extends BeanDeserializerBase
implements java.io.Serializable
{
/* TODOs for future versions:
*
* For 2.8?
*
* - New method in JsonDeserializer (deserializeNext()) to allow use of more
* efficient 'nextXxx()' method `JsonParser` provides.
*
* Also: need to ensure efficient impl of those methods for Smile, CBOR
* at least (in addition to JSON)
*/
private static final long serialVersionUID = 1L;
/**
* Lazily constructed exception used as root cause if reporting problem
* with creator method that returns <code>null</code> (which is not allowed)
*
* @since 3.8
*/
protected transient Exception _nullFromCreator;
/*
/**********************************************************
/* Life-cycle, construction, initialization
/**********************************************************
*/
/**
* Constructor used by {@link BeanDeserializerBuilder}.
*/
public BeanDeserializer(BeanDeserializerBuilder builder, BeanDescription beanDesc,
BeanPropertyMap properties, Map<String, SettableBeanProperty> backRefs,
HashSet<String> ignorableProps, boolean ignoreAllUnknown,
boolean hasViews)
{
super(builder, beanDesc, properties, backRefs,
ignorableProps, ignoreAllUnknown, hasViews);
}
/**
* Copy-constructor that can be used by sub-classes to allow
* copy-on-write style copying of settings of an existing instance.
*/
protected BeanDeserializer(BeanDeserializerBase src) {
super(src, src._ignoreAllUnknown);
}
protected BeanDeserializer(BeanDeserializerBase src, boolean ignoreAllUnknown) {
super(src, ignoreAll
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Unknown);
}
protected BeanDeserializer(BeanDeserializerBase src, NameTransformer unwrapper) {
super(src, unwrapper);
}
public BeanDeserializer(BeanDeserializerBase src, ObjectIdReader oir) {
super(src, oir);
}
public BeanDeserializer(BeanDeserializerBase src, Set<String> ignorableProps) {
super(src, ignorableProps);
}
public BeanDeserializer(BeanDeserializerBase src, BeanPropertyMap props) {
super(src, props);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* bit kludgy but we don't want to accidentally change type; sub-classes
* MUST override this method to support unwrapped properties...
*/
if (getClass() != BeanDeserializer.class) {
return this;
}
/* main thing really is to just enforce ignoring of unknown
* properties; since there may be multiple unwrapped values
* and properties for all may be interleaved...
*/
return new BeanDeserializer(this, unwrapper);
}
@Override
public BeanDeserializer withObjectIdReader(ObjectIdReader oir) {
return new BeanDeserializer(this, oir);
}
@Override
public BeanDeserializer withIgnorableProperties(Set<String> ignorableProps) {
return new BeanDeserializer(this, ignorableProps);
}
@Override
public BeanDeserializerBase withBeanProperties(BeanPropertyMap props) {
return new BeanDeserializer(this, props);
}
@Override
protected BeanDeserializerBase asArrayDeserializer() {
SettableBeanProperty[] props = _beanProperties.getPropertiesInInsertionOrder();
return new BeanAsArrayDeserializer(this, props);
}
/*
/**********************************************************
/* JsonDeserializer implementation
/**********************************************************
*/
/**
* Main deserialization method for bean-based objects (POJOs).
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// common case first
if (p.isExpectedStartObjectToken()) {
if (_vanillaProcessing) {
return vanillaDeserialize(p, ctxt, p.nextToken());
}
// 23-Sep-2015, tatu: This is wrong at some many levels, but for now... it is
// what it is, including "
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> != null) {
return deserializeWithUnwrapped(p, ctxt, bean);
}
if (_externalTypeIdHandler != null) {
return deserializeWithExternalTypeId(p, ctxt, bean);
}
String propName;
// 23-Mar-2010, tatu: In some cases, we start with full JSON object too...
if (p.isExpectedStartObjectToken()) {
propName = p.nextFieldName();
if (propName == null) {
return bean;
}
} else {
if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
propName = p.getCurrentName();
} else {
return bean;
}
}
if (_needViewProcesing) {
Class<?> view = ctxt.getActiveView();
if (view != null) {
return deserializeWithView(p, ctxt, bean, view);
}
}
do {
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
handleUnknownVanilla(p, ctxt, bean, propName);
} while ((propName = p.nextFieldName()) != null);
return bean;
}
/*
/**********************************************************
/* Concrete deserialization methods
/**********************************************************
*/
/**
* Streamlined version that is only used when no "special"
* features are enabled.
*/
private final Object vanillaDeserialize(JsonParser p,
DeserializationContext ctxt, JsonToken t)
throws IOException
{
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
String propName = p.getCurrentName();
do {
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>631]: Assign current value, to be accessible by custom deserializers
p.setCurrentValue(bean);
if (p.canReadObjectId()) {
Object id = p.getObjectId();
if (id != null) {
_handleTypedObjectId(p, ctxt, bean, id);
}
}
if (_injectables != null) {
injectValues(ctxt, bean);
}
if (_needViewProcesing) {
Class<?> view = ctxt.getActiveView();
if (view != null) {
return deserializeWithView(p, ctxt, bean, view);
}
}
if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
String propName = p.getCurrentName();
do {
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
handleUnknownVanilla(p, ctxt, bean, propName);
} while ((propName = p.nextFieldName()) != null);
}
return bean;
}
/**
* Method called to deserialize bean using "property-based creator":
* this means that a non-default constructor or factory method is
* called, and then possibly other setters. The trick is that
* values for creator method need to be buffered, first; and
* due to non-guaranteed ordering possibly some other properties
* as well.
*/
@Override
@SuppressWarnings("resource")
protected Object _deserializeUsingPropertyBased(final JsonParser p, final DeserializationContext ctxt)
throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
TokenBuffer unknown = null;
JsonToken t = p.getCurrentToken();
List<BeanReferring> referrings = null;
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp,
_deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
bean = wrapInstantiationProblem(e, ctxt);
}
if (bean == null) {
return ctxt.handleInstantiationProblem(handledType(), null,
_creatorReturnedNullException());
}
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
return handlePolymorphic(p, ctxt, bean, unknown);
}
if (unknown != null) { // nope, just extra unknown stuff...
bean = handleUnknownProperties(ctxt, bean, unknown);
}
// or just clean?
return deserialize(p, ctxt, bean);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
try {
buffer.bufferProperty(prop, _deserializeWithErrorWrapping(p, ctxt, prop));
} catch (UnresolvedForwardReference reference) {
// 14-Jun-2016, tatu: As per [databind#1261], looks like we need additional
// handling of forward references here. Not exactly sure why existing
// facilities did not cover, but this does appear to solve the problem
BeanReferring referring = handleUnresolvedReference(ctxt,
prop, buffer, reference);
if (referrings == null) {
referrings = new ArrayList<BeanReferring>();
}
referrings.add(referring);
}
continue;
}
// Things marked as ignorable should not be passed to any setter
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> pointing to {@link JsonToken#VALUE_NULL}
* token. While this is most often an erroneous condition, there is one specific
* case with XML handling where polymorphic type with no properties is exposed
* as such, and should be handled same as empty Object.
*
* @since 2.7
*/
protected Object deserializeFromNull(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// 17-Dec-2015, tatu: Highly specialized case, mainly to support polymorphic
// "empty" POJOs deserialized from XML, where empty XML tag synthesizes a
// `VALUE_NULL` token.
if (p.requiresCustomCodec()) { // not only XML module, but mostly it...
@SuppressWarnings("resource")
TokenBuffer tb = new TokenBuffer(p, ctxt);
tb.writeEndObject();
JsonParser p2 = tb.asParser(p);
p2.nextToken(); // to point to END_OBJECT
// note: don't have ObjectId to consider at this point, so:
Object ob = _vanillaProcessing ? vanillaDeserialize(p2, ctxt, JsonToken.END_OBJECT)
: deserializeFromObject(p2, ctxt);
p2.close();
return ob;
}
return ctxt.handleUnexpectedToken(handledType(), p);
}
/*
/**********************************************************
/* Deserializing when we have to consider an active View
/**********************************************************
*/
protected final Object deserializeWithView(JsonParser p, DeserializationContext ctxt,
Object bean, Class<?> activeView)
throws IOException
{
if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
String propName = p.getCurrentName();
do {
p.nextToken();
// TODO: 06-Jan-2015, tatu: try streamlining call sequences here as well
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
if (!prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> }
handleUnknownVanilla(p, ctxt, bean, propName);
} while ((propName = p.nextFieldName()) != null);
}
return bean;
}
/*
/**********************************************************
/* Handling for cases where we have "unwrapped" values
/**********************************************************
*/
/**
* Method called when there are declared "unwrapped" properties
* which need special handling
*/
@SuppressWarnings("resource")
protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_delegateDeserializer != null) {
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt));
}
if (_propertyBasedCreator != null) {
return deserializeUsingPropertyBasedWithUnwrapped(p, ctxt);
}
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
final Object bean = _valueInstantiator.createUsingDefault(ctxt);
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
if (_injectables != null) {
injectValues(ctxt, bean);
}
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
String propName = p.hasTokenId(JsonTokenId.ID_FIELD_NAME) ? p.getCurrentName() : null;
for (; propName != null; propName = p.nextFieldName()) {
p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// Things marked as ignorable should not be passed to any setter
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> tokens.copyCurrentStructure(p);
// how about any setter? We'll get copies but...
if (_anySetter != null) {
try {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
}
tokens.writeEndObject();
_unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
return bean;
}
@SuppressWarnings("resource")
protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext ctxt, Object bean)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.START_OBJECT) {
t = p.nextToken();
}
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
SettableBeanProperty prop = _beanProperties.find(propName);
p.nextToken();
if (prop != null) { // normal case
if (activeView != null && !prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but... others should be passed to unwrapped property deserializers
tokens.writeFieldName(propName);
tokens.copyCurrentStructure(p);
// how about any setter? We'll get copies but...
if (_anySetter != null) {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
}
}
tokens.writeEndObject();
_unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
return bean;
}
@SuppressWarnings("resource")
protected Object deserialize
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>UsingPropertyBasedWithUnwrapped(JsonParser p, DeserializationContext ctxt)
throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
bean = wrapInstantiationProblem(e, ctxt);
}
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
// if so, need to copy all remaining tokens into buffer
while (t == JsonToken.FIELD_NAME) {
p.nextToken(); // to skip name
tokens.copyCurrentStructure(p);
t = p.nextToken();
}
tokens.writeEndObject();
if (bean.getClass() != _beanType.getRawClass()) {
// !!! 08-Jul-2011, tatu: Could probably support; but for now
// it's too complicated, so bail out
tokens.close();
ctxt.reportMappingException("Can not create polymorphic instances with unwrapped values");
return null;
}
return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, _deserializeWithErrorWrapping(p,
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>TypeIdHandler.start();
for (JsonToken t = p.getCurrentToken(); t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
t = p.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
// [JACKSON-831]: may have property AND be used as external type id:
if (t.isScalarValue()) {
ext.handleTypePropertyValue(p, ctxt, propName, bean);
}
if (activeView != null && !prop.visibleInView(activeView)) {
p.skipChildren();
continue;
}
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// ignorable things should be ignored
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt, bean, propName);
continue;
}
// but others are likely to be part of external type id thingy...
if (ext.handlePropertyValue(p, ctxt, propName, bean)) {
continue;
}
// if not, the usual fallback handling:
if (_anySetter != null) {
try {
_anySetter.deserializeAndSet(p, ctxt, bean, propName);
} catch (Exception e) {
wrapAndThrow(e, bean, propName, ctxt);
}
continue;
}
// Unknown: let's call handler method
handleUnknownProperty(p, ctxt, bean, propName);
}
// and when we get this far, let's try finalizing the deal:
return ext.complete(p, ctxt, bean);
}
@SuppressWarnings("resource")
protected Object deserializeUsingPropertyBasedWithExternalTypeId(JsonParser p, DeserializationContext ctxt)
throws IOException
{
final ExternalTypeHandler ext = _externalTypeIdHandler.start();
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
Json
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Token t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// first: let's check to see if this might be part of value with external type id:
// 11-Sep-2015, tatu: Important; do NOT pass buffer as last arg, but null,
// since it is not the bean
if (ext.handlePropertyValue(p, ctxt, propName, null)) {
;
} else {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue; // never gets here
}
// if so, need to copy all remaining tokens into buffer
while (t == JsonToken.FIELD_NAME) {
p.nextToken(); // to skip name
tokens.copyCurrentStructure(p);
t = p.nextToken();
}
if (bean.getClass() != _beanType.getRawClass()) {
// !!! 08-Jul-2011, tatu: Could theoretically support; but for now
// it's too complicated, so bail out
ctxt.reportMappingException("Can not create polymorphic instances with external type ids");
return null;
}
return ext.complete(p, ctxt, bean);
}
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, prop.deserialize(p, ctxt));
continue;
}
// external type id (or property that depends on it)?
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>PropertyName propertyName) {
return _properties.get(propertyName.getSimpleName());
}
public boolean hasProperty(PropertyName propertyName) {
return findProperty(propertyName) != null;
}
public SettableBeanProperty removeProperty(PropertyName name) {
return _properties.remove(name.getSimpleName());
}
public SettableAnyProperty getAnySetter() {
return _anySetter;
}
public ValueInstantiator getValueInstantiator() {
return _valueInstantiator;
}
public List<ValueInjector> getInjectables() {
return _injectables;
}
public ObjectIdReader getObjectIdReader() {
return _objectIdReader;
}
public AnnotatedMethod getBuildMethod() {
return _buildMethod;
}
public JsonPOJOBuilder.Value getBuilderConfig() {
return _builderConfig;
}
/*
/**********************************************************
/* Build method(s)
/**********************************************************
*/
/**
* Method for constructing a {@link BeanDeserializer}, given all
* information collected.
*/
public JsonDeserializer<?> build()
{
Collection<SettableBeanProperty> props = _properties.values();
BeanPropertyMap propertyMap = BeanPropertyMap.construct(props, _caseInsensitivePropertyComparison);
propertyMap.assignIndexes();
// view processing must be enabled if:
// (a) fields are not included by default (when deserializing with view), OR
// (b) one of properties has view(s) to included in defined
boolean anyViews = !_defaultViewInclusion;
if (!anyViews) {
for (SettableBeanProperty prop : props) {
if (prop.hasViews()) {
anyViews = true;
break;
}
}
}
// one more thing: may need to create virtual ObjectId property:
if (_objectIdReader != null) {
/* 18-Nov-2012, tatu: May or may not have annotations for id property;
* but no easy access. But hard to see id property being optional,
* so let's consider required at this point.
*/
ObjectIdValueProperty prop = new ObjectIdValueProperty(_objectIdReader, PropertyMetadata.STD_REQUIRED);
propertyMap = propertyMap.withProperty(prop);
}
return new BeanDeserializer(this,
_beanDesc, propertyMap, _backRefProperties,
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> _ignorableProps, _ignoreAllUnknown,
anyViews);
}
/**
* Alternate build method used when we must be using some form of
* abstract resolution, usually by using addition Type Id
* ("polymorphic deserialization")
*
* @since 2.0
*/
public AbstractDeserializer buildAbstract() {
return new AbstractDeserializer(this, _beanDesc, _backRefProperties);
}
/**
* Method for constructing a specialized deserializer that uses
* additional external Builder object during data binding.
*/
public JsonDeserializer<?> buildBuilderBased(JavaType valueType,
String expBuildMethodName)
{
// First: validation; must have build method that returns compatible type
if (_buildMethod == null) {
// as per [databind#777], allow empty name
if (!expBuildMethodName.isEmpty()) {
throw new IllegalArgumentException("Builder class "+_beanDesc.getBeanClass().getName()
+" does not have build method (name: '"+expBuildMethodName+"')");
}
} else {
// also: type of the method must be compatible
Class<?> rawBuildType = _buildMethod.getRawReturnType();
Class<?> rawValueType = valueType.getRawClass();
if ((rawBuildType != rawValueType)
&& !rawBuildType.isAssignableFrom(rawValueType)
&& !rawValueType.isAssignableFrom(rawBuildType)) {
throw new IllegalArgumentException("Build method '"+_buildMethod.getFullName()
+" has bad return type ("+rawBuildType.getName()
+"), not compatible with POJO type ("+valueType.getRawClass().getName()+")");
}
}
// And if so, we can try building the deserializer
Collection<SettableBeanProperty> props = _properties.values();
BeanPropertyMap propertyMap = BeanPropertyMap.construct(props, _caseInsensitivePropertyComparison);
propertyMap.assignIndexes();
boolean anyViews = !_defaultViewInclusion;
if (!anyViews) {
for (SettableBeanProperty prop : props) {
if (prop.hasViews()) {
anyViews = true;
break;
}
}
}
if (_objectIdReader != null) {
/* 18-Nov-2012, tatu: May or may not have annotations for id property;
* but no easy access. But hard
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.util;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.type.ClassKey;
/**
* Helper class for caching resolved root names.
*/
public class RootNameLookup implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* For efficient operation, let's try to minimize number of times we
* need to introspect root element name to use.
*/
protected transient LRUMap<ClassKey,PropertyName> _rootNames;
public RootNameLookup() {
_rootNames = new LRUMap<ClassKey,PropertyName>(20, 200);
}
public PropertyName findRootName(JavaType rootType, MapperConfig<?> config) {
return findRootName(rootType.getRawClass(), config);
}
public PropertyName findRootName(Class<?> rootType, MapperConfig<?> config)
{
ClassKey key = new ClassKey(rootType);
PropertyName name = _rootNames.get(key);
if (name != null) {
return name;
}
BeanDescription beanDesc = config.introspectClassAnnotations(rootType);
AnnotationIntrospector intr = config.getAnnotationIntrospector();
AnnotatedClass ac = beanDesc.getClassInfo();
name = intr.findRootName(ac);
// No answer so far? Let's just default to using simple class name
if (name == null || !name.hasSimpleName()) {
// Should we strip out enclosing class tho? For now, nope:
name = PropertyName.construct(rootType.getSimpleName());
}
_rootNames.put(key, name);
return name;
}
/*
/**********************************************************
/* Serializable overrides
/**********************************************************
*/
/**
* Need to override to reproduce cache object via constructor, instead
* of serialize/deserialize (since we do NOT want to retain cached data)
*/
protected Object readResolve() {
return new RootNameLookup();
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> so:
throw new JsonParseException(null, "Can not use source of type "
+src.getClass().getName()+" with format auto-detection: must be byte- not char-based");
}
protected InputStream _inputStream(URL src) throws IOException {
return src.openStream();
}
protected InputStream _inputStream(File f) throws IOException {
return new FileInputStream(f);
}
/*
/**********************************************************
/* Helper methods, locating deserializers etc
/**********************************************************
*/
/**
* Method called to locate deserializer for the passed root-level value.
*/
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt)
throws JsonMappingException
{
if (_rootDeserializer != null) {
return _rootDeserializer;
}
// Sanity check: must have actual type...
JavaType t = _valueType;
if (t == null) {
ctxt.reportMappingException("No value type configured for ObjectReader");
}
// First: have we already seen it?
JsonDeserializer<Object> deser = _rootDeserializers.get(t);
if (deser != null) {
return deser;
}
// Nope: need to ask provider to resolve it
deser = ctxt.findRootValueDeserializer(t);
if (deser == null) { // can this happen?
ctxt.reportMappingException("Can not find a deserializer for type %s", t);
}
_rootDeserializers.put(t, deser);
return deser;
}
/**
* @since 2.6
*/
protected JsonDeserializer<Object> _findTreeDeserializer(DeserializationContext ctxt)
throws JsonMappingException
{
JsonDeserializer<Object> deser = _rootDeserializers.get(JSON_NODE_TYPE);
if (deser == null) {
// Nope: need to ask provider to resolve it
deser = ctxt.findRootValueDeserializer(JSON_NODE_TYPE);
if (deser == null) { // can this happen?
ctxt.reportMappingException("Can not find a deserializer for type %s",
JSON_NODE_TYPE);
}
_rootDeserializers.put(JSON_NODE_TYPE, deser);
}
return deser;
}
/**
* Method called to locate deserializer ahead of time, if permitted
* by configuration
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>. Method also is NOT to throw an exception if
* access fails.
*/
protected JsonDeserializer<Object> _prefetchRootDeserializer(JavaType valueType)
{
if (valueType == null || !_config.isEnabled(DeserializationFeature.EAGER_DESERIALIZER_FETCH)) {
return null;
}
// already cached?
JsonDeserializer<Object> deser = _rootDeserializers.get(valueType);
if (deser == null) {
try {
// If not, need to resolve; for which we need a temporary context as well:
DeserializationContext ctxt = createDeserializationContext(null);
deser = ctxt.findRootValueDeserializer(valueType);
if (deser != null) {
_rootDeserializers.put(valueType, deser);
}
return deser;
} catch (JsonProcessingException e) {
// need to swallow?
}
}
return deser;
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>-Nov-2015, tatu: Only avoid wrapping if already a JsonMappingException
if (t instanceof JsonMappingException) {
return (JsonMappingException) t;
}
return ctxt.instantiationException(getValueClass(), t);
}
/**
* @since 2.7
*/
protected JsonMappingException rewrapCtorProblem(DeserializationContext ctxt,
Throwable t)
{
// 05-Nov-2015, tatu: Seems like there are really only 2 useless wrapper errors/exceptions,
// so just peel those, and nothing else
if ((t instanceof ExceptionInInitializerError) // from static initialization block
|| (t instanceof InvocationTargetException) // from constructor/method
) {
Throwable cause = t.getCause();
if (cause != null) {
t = cause;
}
}
return wrapAsJsonMappingException(ctxt, t);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
private Object _createUsingDelegate(
AnnotatedWithParams delegateCreator,
SettableBeanProperty[] delegateArguments,
DeserializationContext ctxt,
Object delegate)
throws IOException
{
if (delegateCreator == null) { // sanity-check; caller should check
throw new IllegalStateException("No delegate constructor for "+getValueTypeDesc());
}
try {
// First simple case: just delegate, no injectables
if (delegateArguments == null) {
return delegateCreator.call1(delegate);
}
// And then the case with at least one injectable...
final int len = delegateArguments.length;
Object[] args = new Object[len];
for (int i = 0; i < len; ++i) {
SettableBeanProperty prop = delegateArguments[i];
if (prop == null) { // delegate
args[i] = delegate;
} else { // nope, injectable:
args[i] = ctxt.findInjectableValue(prop.getInjectableValueId(), prop, null);
}
}
// and then try calling with full set of arguments
return delegateCreator.call(args);
} catch (Throwable t) {
throw rewrapCtorProblem(ctxt, t);
}
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.type.ReferenceType;
import com.fasterxml.jackson.databind.util.NameTransformer;
public class AtomicReferenceSerializer
extends ReferenceTypeSerializer<AtomicReference<?>>
{
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Constructors, factory methods
/**********************************************************
*/
public AtomicReferenceSerializer(ReferenceType fullType, boolean staticTyping,
TypeSerializer vts, JsonSerializer<Object> ser)
{
super(fullType, staticTyping, vts, ser);
}
protected AtomicReferenceSerializer(AtomicReferenceSerializer base, BeanProperty property,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper,
JsonInclude.Include contentIncl)
{
super(base, property, vts, valueSer, unwrapper, contentIncl);
}
@Override
protected AtomicReferenceSerializer withResolved(BeanProperty prop,
TypeSerializer vts, JsonSerializer<?> valueSer,
NameTransformer unwrapper,
JsonInclude.Include contentIncl)
{
if ((_property == prop) && (contentIncl == _contentInclusion)
&& (_valueTypeSerializer == vts) && (_valueSerializer == valueSer)
&& (_unwrapper == unwrapper)) {
return this;
}
return new AtomicReferenceSerializer(this, prop, vts, valueSer, unwrapper, contentIncl);
}
/*
/**********************************************************
/* Abstract method impls
/**********************************************************
*/
@Override
protected boolean _isValueEmpty(AtomicReference<?> value) {
return value.get() == null;
}
@Override
protected Object _getReferenced(AtomicReference<?> value) {
return value.get();
}
@Override
protected Object _getReferencedIfPresent(AtomicReference<?> value) {
return value.get();
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> use {@link #findEnumValues} instead because this method
* does not properly handle override settings (defaults to <code>enum.name</code>
* without indicating whether that is explicit or not), and is inefficient to
* call one-by-one.
*/
@Deprecated
public String findEnumValue(Enum<?> value) {
return value.name();
}
/**
* Method for efficiently figuring out which if given set of <code>Enum</code> values
* have explicitly defined name. Method will overwrite entries in incoming <code>names</code>
* array with explicit names found, if any, leaving other entries unmodified.
*<p>
* Default implementation will simply delegate to {@link #findEnumValue}, which is close
* enough, although unfortunately NOT 100% equivalent (as it will also consider <code>name()</code>
* to give explicit value).
*
* @since 2.7
*/
public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[] names) {
for (int i = 0, len = enumValues.length; i < len; ++i) {
/* 12-Mar-2016, tatu: This is quite tricky, considering that we should NOT
* overwrite values with default `name`... so for now, let's only delegate
* if no value has been set. Still not optimal but has to do
*/
// TODO: In 2.8, stop delegation?
if (names[i] == null) {
names[i] = findEnumValue(enumValues[i]);
}
}
return names;
}
/**
* Finds the Enum value that should be considered the default value, if possible.
*
* @param enumCls The Enum class to scan for the default value.
* @return null if none found or it's not possible to determine one.
*
* @since 2.8
*/
public Enum<?> findDefaultEnumValue(Class<Enum<?>> enumCls) {
return null;
}
/*
/**********************************************************
/* Deserialization: general annotations
/**********************************************************
*/
/**
* Method for getting a deserializer definition on specified method
* or field.
* Type of definition is either instance (of
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>need to add/enable type information?)");
}
boolean hasStringCreator = _valueInstantiator.canCreateFromString();
boolean hasDefaultCtor = _valueInstantiator.canCreateUsingDefault();
// and finally, verify we do have single-String arg constructor (if no @JsonCreator)
if (!hasStringCreator && !hasDefaultCtor) {
return ctxt.handleMissingInstantiator(handledType(), p,
"Throwable needs a default contructor, a single-String-arg constructor; or explicit @JsonCreator");
}
Object throwable = null;
Object[] pending = null;
int pendingIx = 0;
for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
String propName = p.getCurrentName();
SettableBeanProperty prop = _beanProperties.find(propName);
p.nextToken(); // to point to field value
if (prop != null) { // normal case
if (throwable != null) {
prop.deserializeAndSet(p, ctxt, throwable);
continue;
}
// nope; need to defer
if (pending == null) {
int len = _beanProperties.size();
pending = new Object[len + len];
}
pending[pendingIx++] = prop;
pending[pendingIx++] = prop.deserialize(p, ctxt);
continue;
}
// Maybe it's "message"?
if (PROP_NAME_MESSAGE.equals(propName)) {
if (hasStringCreator) {
throwable = _valueInstantiator.createFromString(ctxt, p.getText());
// any pending values?
if (pending != null) {
for (int i = 0, len = pendingIx; i < len; i += 2) {
prop = (SettableBeanProperty)pending[i];
prop.set(throwable, pending[i+1]);
}
pending = null;
}
continue;
}
}
/* As per [JACKSON-313], things marked as ignorable should not be
* passed to any setter
*/
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
p.skipChildren();
continue;
}
if (_anySetter != null) {
_anySetter.deserializeAndSet(p, ctxt, throwable, prop
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Name);
continue;
}
// Unknown: let's call handler method
handleUnknownProperty(p, ctxt, throwable, propName);
}
// Sanity check: did we find "message"?
if (throwable == null) {
/* 15-Oct-2010, tatu: Can't assume missing message is an error, since it may be
* suppressed during serialization, as per [JACKSON-388].
*
* Should probably allow use of default constructor, too...
*/
//throw new JsonMappingException("No 'message' property found: could not deserialize "+_beanType);
if (hasStringCreator) {
throwable = _valueInstantiator.createFromString(ctxt, null);
} else {
throwable = _valueInstantiator.createUsingDefault(ctxt);
}
// any pending values?
if (pending != null) {
for (int i = 0, len = pendingIx; i < len; i += 2) {
SettableBeanProperty prop = (SettableBeanProperty)pending[i];
prop.set(throwable, pending[i+1]);
}
}
}
return throwable;
}
}
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>package com.fasterxml.jackson.databind.node;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.util.RawValue;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
/**
* Node that maps to JSON Object structures in JSON content.
*<p>
* Note: class was <code>final</code> temporarily for Jackson 2.2.
*/
public class ObjectNode
extends ContainerNode<ObjectNode>
{
// Note: LinkedHashMap for backwards compatibility
protected final Map<String, JsonNode> _children;
public ObjectNode(JsonNodeFactory nc) {
super(nc);
_children = new LinkedHashMap<String, JsonNode>();
}
/**
* @since 2.4
*/
public ObjectNode(JsonNodeFactory nc, Map<String, JsonNode> kids) {
super(nc);
_children = kids;
}
@Override
protected JsonNode _at(JsonPointer ptr) {
return get(ptr.getMatchingProperty());
}
/* Question: should this delegate to `JsonNodeFactory`? It does not absolutely
* have to, as long as sub-types override the method but...
*/
// note: co-variant for type safety
@SuppressWarnings("unchecked")
@Override
public ObjectNode deepCopy()
{
ObjectNode ret = new ObjectNode(_nodeFactory);
for (Map.Entry<String, JsonNode> entry: _children.entrySet())
ret._children.put(entry.getKey(), entry.getValue().deepCopy());
return ret;
}
/*
/**********************************************************
/* Overrides for JsonSerializable.Base
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider serializers) {
return _children.isEmpty();
}
/*
/**********************************************************
/* Implementation of core JsonNode API
/**********************************************************
*/
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.OBJECT;
}
@Override public JsonToken asToken() { return JsonToken.START_OBJECT; }
@Override
public int size() {
return _children.size();
}
@Override
public Iterator<JsonNode> elements() {
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
return _children.values().iterator();
}
@Override
public JsonNode get(int index) { return null; }
@Override
public JsonNode get(String fieldName) {
return _children.get(fieldName);
}
@Override
public Iterator<String> fieldNames() {
return _children.keySet().iterator();
}
@Override
public JsonNode path(int index) {
return MissingNode.getInstance();
}
@Override
public JsonNode path(String fieldName)
{
JsonNode n = _children.get(fieldName);
if (n != null) {
return n;
}
return MissingNode.getInstance();
}
/**
* Method to use for accessing all fields (with both names
* and values) of this JSON Object.
*/
@Override
public Iterator<Map.Entry<String, JsonNode>> fields() {
return _children.entrySet().iterator();
}
@Override
public ObjectNode with(String propertyName) {
JsonNode n = _children.get(propertyName);
if (n != null) {
if (n instanceof ObjectNode) {
return (ObjectNode) n;
}
throw new UnsupportedOperationException("Property '" + propertyName
+ "' has value that is not of type ObjectNode (but " + n
.getClass().getName() + ")");
}
ObjectNode result = objectNode();
_children.put(propertyName, result);
return result;
}
@Override
public ArrayNode withArray(String propertyName)
{
JsonNode n = _children.get(propertyName);
if (n != null) {
if (n instanceof ArrayNode) {
return (ArrayNode) n;
}
throw new UnsupportedOperationException("Property '" + propertyName
+ "' has value that is not of type ArrayNode (but " + n
.getClass().getName() + ")");
}
ArrayNode result = arrayNode();
_children.put(propertyName, result);
return result;
}
@Override
public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
{
if (!(o instanceof ObjectNode)) {
return false;
}
ObjectNode other = (ObjectNode) o;
Map<String, JsonNode> m1 = _children;
Map<String, JsonNode> m2 = other._children;
final int len = m1.size();
if (m2
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>.size() != len) {
return false;
}
for (Map.Entry<String, JsonNode> entry : m1.entrySet()) {
JsonNode v2 = m2.get(entry.getKey());
if ((v2 == null) || !entry.getValue().equals(comparator, v2)) {
return false;
}
}
return true;
}
/*
/**********************************************************
/* Public API, finding value nodes
/**********************************************************
*/
@Override
public JsonNode findValue(String fieldName)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
return entry.getValue();
}
JsonNode value = entry.getValue().findValue(fieldName);
if (value != null) {
return value;
}
}
return null;
}
@Override
public List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
if (foundSoFar == null) {
foundSoFar = new ArrayList<JsonNode>();
}
foundSoFar.add(entry.getValue());
} else { // only add children if parent not added
foundSoFar = entry.getValue().findValues(fieldName, foundSoFar);
}
}
return foundSoFar;
}
@Override
public List<String> findValuesAsText(String fieldName, List<String> foundSoFar)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
if (foundSoFar == null) {
foundSoFar = new ArrayList<String>();
}
foundSoFar.add(entry.getValue().asText());
} else { // only add children if parent not added
foundSoFar = entry.getValue().findValuesAsText(fieldName,
foundSoFar);
}
}
return foundSoFar;
}
@Override
public ObjectNode findParent(String fieldName)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
return this
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> void serialize(JsonGenerator gen) throws IOException
{
Segment segment = _first;
int ptr = -1;
final boolean checkIds = _mayHaveNativeIds;
boolean hasIds = checkIds && (segment.hasIds());
while (true) {
if (++ptr >= Segment.TOKENS_PER_SEGMENT) {
ptr = 0;
segment = segment.next();
if (segment == null) break;
hasIds = checkIds && (segment.hasIds());
}
JsonToken t = segment.type(ptr);
if (t == null) break;
if (hasIds) {
Object id = segment.findObjectId(ptr);
if (id != null) {
gen.writeObjectId(id);
}
id = segment.findTypeId(ptr);
if (id != null) {
gen.writeTypeId(id);
}
}
// Note: copied from 'copyCurrentEvent'...
switch (t) {
case START_OBJECT:
gen.writeStartObject();
break;
case END_OBJECT:
gen.writeEndObject();
break;
case START_ARRAY:
gen.writeStartArray();
break;
case END_ARRAY:
gen.writeEndArray();
break;
case FIELD_NAME:
{
// 13-Dec-2010, tatu: Maybe we should start using different type tokens to reduce casting?
Object ob = segment.get(ptr);
if (ob instanceof SerializableString) {
gen.writeFieldName((SerializableString) ob);
} else {
gen.writeFieldName((String) ob);
}
}
break;
case VALUE_STRING:
{
Object ob = segment.get(ptr);
if (ob instanceof SerializableString) {
gen.writeString((SerializableString) ob);
} else {
gen.writeString((String) ob);
}
}
break;
case VALUE_NUMBER_INT:
{
Object n = segment.get(ptr);
if (n instanceof Integer) {
gen.writeNumber((Integer) n);
} else if (n instanceof BigInteger) {
gen.writeNumber((BigInteger) n);
} else if (n instanceof Long) {
gen.writeNumber((Long) n);
} else if (n instanceof Short) {
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>
gen.writeNumber((Short) n);
} else {
gen.writeNumber(((Number) n).intValue());
}
}
break;
case VALUE_NUMBER_FLOAT:
{
Object n = segment.get(ptr);
if (n instanceof Double) {
gen.writeNumber(((Double) n).doubleValue());
} else if (n instanceof BigDecimal) {
gen.writeNumber((BigDecimal) n);
} else if (n instanceof Float) {
gen.writeNumber(((Float) n).floatValue());
} else if (n == null) {
gen.writeNull();
} else if (n instanceof String) {
gen.writeNumber((String) n);
} else {
throw new JsonGenerationException(String.format(
"Unrecognized value type for VALUE_NUMBER_FLOAT: %s, can not serialize",
n.getClass().getName()), gen);
}
}
break;
case VALUE_TRUE:
gen.writeBoolean(true);
break;
case VALUE_FALSE:
gen.writeBoolean(false);
break;
case VALUE_NULL:
gen.writeNull();
break;
case VALUE_EMBEDDED_OBJECT:
{
Object value = segment.get(ptr);
if (value instanceof RawValue) {
((RawValue) value).serialize(gen);
} else {
gen.writeObject(value);
}
}
break;
default:
throw new RuntimeException("Internal error: should never end up through this code path");
}
}
}
/**
* Helper method used by standard deserializer.
*
* @since 2.3
*/
public TokenBuffer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
if (p.getCurrentTokenId() != JsonToken.FIELD_NAME.id()) {
copyCurrentStructure(p);
return this;
}
/* 28-Oct-2014, tatu: As per [databind#592], need to support a special case of starting from
* FIELD_NAME, which is taken to mean that we are missing START_OBJECT, but need
* to assume one did exist.
*/
JsonToken t;
writeStartObject();
do {
copyCurrentStructure(p);
} while ((t = p.
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>();
_append(JsonToken.START_ARRAY);
_writeContext = _writeContext.createChildArrayContext();
}
@Override
public final void writeEndArray() throws IOException
{
_append(JsonToken.END_ARRAY);
// Let's allow unbalanced tho... i.e. not run out of root level, ever
JsonWriteContext c = _writeContext.getParent();
if (c != null) {
_writeContext = c;
}
}
@Override
public final void writeStartObject() throws IOException
{
_writeContext.writeValue();
_append(JsonToken.START_OBJECT);
_writeContext = _writeContext.createChildObjectContext();
}
@Override // since 2.8
public void writeStartObject(Object forValue) throws IOException
{
_writeContext.writeValue();
_append(JsonToken.START_OBJECT);
JsonWriteContext ctxt = _writeContext.createChildObjectContext();
_writeContext = ctxt;
if (forValue != null) {
ctxt.setCurrentValue(forValue);
}
}
@Override
public final void writeEndObject() throws IOException
{
_append(JsonToken.END_OBJECT);
// Let's allow unbalanced tho... i.e. not run out of root level, ever
JsonWriteContext c = _writeContext.getParent();
if (c != null) {
_writeContext = c;
}
}
@Override
public final void writeFieldName(String name) throws IOException
{
_writeContext.writeFieldName(name);
_append(JsonToken.FIELD_NAME, name);
}
@Override
public void writeFieldName(SerializableString name) throws IOException
{
_writeContext.writeFieldName(name.getValue());
_append(JsonToken.FIELD_NAME, name);
}
/*
/**********************************************************
/* JsonGenerator implementation: write methods, textual
/**********************************************************
*/
@Override
public void writeString(String text) throws IOException {
if (text == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_STRING, text);
}
}
@Override
public void writeString(char[] text, int offset, int len) throws IOException {
writeString(new String(text
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>, offset, len));
}
@Override
public void writeString(SerializableString text) throws IOException {
if (text == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_STRING, text);
}
}
@Override
public void writeRawUTF8String(byte[] text, int offset, int length) throws IOException
{
// could add support for buffering if we really want it...
_reportUnsupportedOperation();
}
@Override
public void writeUTF8String(byte[] text, int offset, int length) throws IOException
{
// could add support for buffering if we really want it...
_reportUnsupportedOperation();
}
@Override
public void writeRaw(String text) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(String text, int offset, int len) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(SerializableString text) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(char[] text, int offset, int len) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(char c) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRawValue(String text) throws IOException {
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, new RawValue(text));
}
@Override
public void writeRawValue(String text, int offset, int len) throws IOException {
if (offset > 0 || len != text.length()) {
text = text.substring(offset, offset+len);
}
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, new RawValue(text));
}
@Override
public void writeRawValue(char[] text, int offset, int len) throws IOException {
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, new String(text, offset, len));
}
/*
/**********************************************************
/* JsonGenerator implementation: write methods, primitive types
/**********************************************************
*/
@Override
public void writeNumber(short i) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_INT, Short.valueOf(i));
}
@
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>Override
public void writeNumber(int i) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_INT, Integer.valueOf(i));
}
@Override
public void writeNumber(long l) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_INT, Long.valueOf(l));
}
@Override
public void writeNumber(double d) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, Double.valueOf(d));
}
@Override
public void writeNumber(float f) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, Float.valueOf(f));
}
@Override
public void writeNumber(BigDecimal dec) throws IOException {
if (dec == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, dec);
}
}
@Override
public void writeNumber(BigInteger v) throws IOException {
if (v == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_NUMBER_INT, v);
}
}
@Override
public void writeNumber(String encodedValue) throws IOException {
/* 03-Dec-2010, tatu: related to [JACKSON-423], should try to keep as numeric
* identity as long as possible
*/
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, encodedValue);
}
@Override
public void writeBoolean(boolean state) throws IOException {
_appendValue(state ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE);
}
@Override
public void writeNull() throws IOException {
_appendValue(JsonToken.VALUE_NULL);
}
/*
/***********************************************************
/* JsonGenerator implementation: write methods for POJOs/trees
/***********************************************************
*/
@Override
public void writeObject(Object value) throws IOException
{
if (value == null) {
writeNull();
return;
}
Class<?> raw = value.getClass();
if (raw == byte[].class || (value instanceof RawValue)) {
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, value);
return;
}
if (_objectCodec == null) {
/*
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>28-May-2014, tatu: Tricky choice here; if no codec, should we
* err out, or just embed? For now, do latter.
*/
// throw new JsonMappingException("No ObjectCodec configured for TokenBuffer, writeObject() called");
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, value);
} else {
_objectCodec.writeValue(this, value);
}
}
@Override
public void writeTree(TreeNode node) throws IOException
{
if (node == null) {
writeNull();
return;
}
if (_objectCodec == null) {
// as with 'writeObject()', is codec optional?
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, node);
} else {
_objectCodec.writeTree(this, node);
}
}
/*
/***********************************************************
/* JsonGenerator implementation; binary
/***********************************************************
*/
@Override
public void writeBinary(Base64Variant b64variant, byte[] data, int offset, int len) throws IOException
{
/* 31-Dec-2009, tatu: can do this using multiple alternatives; but for
* now, let's try to limit number of conversions.
* The only (?) tricky thing is that of whether to preserve variant,
* seems pointless, so let's not worry about it unless there's some
* compelling reason to.
*/
byte[] copy = new byte[len];
System.arraycopy(data, offset, copy, 0, len);
writeObject(copy);
}
/**
* Although we could support this method, it does not necessarily make
* sense: we can not make good use of streaming because buffer must
* hold all the data. Because of this, currently this will simply
* throw {@link UnsupportedOperationException}
*/
@Override
public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength) {
throw new UnsupportedOperationException();
}
/*
/***********************************************************
/* JsonGenerator implementation: native ids
/***********************************************************
*/
@Override
public boolean canWriteTypeId() {
return _hasNativeTypeIds;
}
@Override
public boolean canWriteObjectId() {
return _hasNativeObjectIds
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> null;
int ptr = _segmentPtr+1;
if (ptr < Segment.TOKENS_PER_SEGMENT && _segment.type(ptr) == JsonToken.FIELD_NAME) {
_segmentPtr = ptr;
Object ob = _segment.get(ptr); // inlined _currentObject();
String name = (ob instanceof String) ? ((String) ob) : ob.toString();
_parsingContext.setCurrentName(name);
return name;
}
return (nextToken() == JsonToken.FIELD_NAME) ? getCurrentName() : null;
}
@Override
public boolean isClosed() { return _closed; }
/*
/**********************************************************
/* Public API, token accessors
/**********************************************************
*/
@Override
public JsonStreamContext getParsingContext() { return _parsingContext; }
@Override
public JsonLocation getTokenLocation() { return getCurrentLocation(); }
@Override
public JsonLocation getCurrentLocation() {
return (_location == null) ? JsonLocation.NA : _location;
}
@Override
public String getCurrentName() {
// 25-Jun-2015, tatu: as per [databind#838], needs to be same as ParserBase
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
JsonReadContext parent = _parsingContext.getParent();
return parent.getCurrentName();
}
return _parsingContext.getCurrentName();
}
@Override
public void overrideCurrentName(String name)
{
// Simple, but need to look for START_OBJECT/ARRAY's "off-by-one" thing:
JsonReadContext ctxt = _parsingContext;
if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) {
ctxt = ctxt.getParent();
}
try {
ctxt.setCurrentName(name);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/*
/**********************************************************
/* Public API, access to token information, text
/**********************************************************
*/
@Override
public String getText()
{
// common cases first:
if (_currToken == JsonToken.VALUE_STRING
|| _currToken == JsonToken.FIELD_NAME) {
Object ob = _currentObject();
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> = _currentObject();
if (ob instanceof byte[]) {
return (byte[]) ob;
}
// fall through to error case
}
if (_currToken != JsonToken.VALUE_STRING) {
throw _constructError("Current token ("+_currToken+") not VALUE_STRING (or VALUE_EMBEDDED_OBJECT with byte[]), can not access as binary");
}
final String str = getText();
if (str == null) {
return null;
}
ByteArrayBuilder builder = _byteBuilder;
if (builder == null) {
_byteBuilder = builder = new ByteArrayBuilder(100);
} else {
_byteBuilder.reset();
}
_decodeBase64(str, builder, b64variant);
return builder.toByteArray();
}
@Override
public int readBinaryValue(Base64Variant b64variant, OutputStream out) throws IOException
{
byte[] data = getBinaryValue(b64variant);
if (data != null) {
out.write(data, 0, data.length);
return data.length;
}
return 0;
}
/*
/**********************************************************
/* Public API, native ids
/**********************************************************
*/
@Override
public boolean canReadObjectId() {
return _hasNativeObjectIds;
}
@Override
public boolean canReadTypeId() {
return _hasNativeTypeIds;
}
@Override
public Object getTypeId() {
return _segment.findTypeId(_segmentPtr);
}
@Override
public Object getObjectId() {
return _segment.findObjectId(_segmentPtr);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected final Object _currentObject() {
return _segment.get(_segmentPtr);
}
protected final void _checkIsNumber() throws JsonParseException
{
if (_currToken == null || !_currToken.isNumeric()) {
throw _constructError("Current token ("+_currToken+") not numeric, can not use numeric value accessors");
}
}
@Override
protected void _handleEOF() throws JsonParseException {
_throwInternal();
}
}
/**
* Individual segment of TokenBuffer that can store up to 16 tokens
* (limited by 4 bits per token type marker requirement).
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS> * Current implementation uses fixed length array; could alternatively
* use 16 distinct fields and switch statement (slightly more efficient
* storage, slightly slower access)
*/
protected final static class Segment
{
public final static int TOKENS_PER_SEGMENT = 16;
/**
* Static array used for fast conversion between token markers and
* matching {@link JsonToken} instances
*/
private final static JsonToken[] TOKEN_TYPES_BY_INDEX;
static {
// ... here we know that there are <= 15 values in JsonToken enum
TOKEN_TYPES_BY_INDEX = new JsonToken[16];
JsonToken[] t = JsonToken.values();
// and reserve entry 0 for "not available"
System.arraycopy(t, 1, TOKEN_TYPES_BY_INDEX, 1, Math.min(15, t.length - 1));
}
// // // Linking
protected Segment _next;
// // // State
/**
* Bit field used to store types of buffered tokens; 4 bits per token.
* Value 0 is reserved for "not in use"
*/
protected long _tokenTypes;
// Actual tokens
protected final Object[] _tokens = new Object[TOKENS_PER_SEGMENT];
/**
* Lazily constructed Map for storing native type and object ids, if any
*/
protected TreeMap<Integer,Object> _nativeIds;
public Segment() { }
// // // Accessors
public JsonToken type(int index)
{
long l = _tokenTypes;
if (index > 0) {
l >>= (index << 2);
}
int ix = ((int) l) & 0xF;
return TOKEN_TYPES_BY_INDEX[ix];
}
public int rawType(int index)
{
long l = _tokenTypes;
if (index > 0) {
l >>= (index << 2);
}
int ix = ((int) l) & 0xF;
return ix;
}
public Object get(int index) {
return _tokens[index];
}
public Segment next() { return _next; }
/**
* Accessor for checking whether this segment may have native
* type or object ids.
*/
public boolean hasIds()
JacksonDatabind, 52
<FILEB>
<CHANGES>
_externalTypeIdHandler = extTypes.build(_beanProperties);
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
public ExternalTypeHandler build(BeanPropertyMap otherProps) {
<CHANGEE>
<CHANGES>
final int len = _properties.size();
ExtTypedProperty[] extProps = new ExtTypedProperty[len];
for (int i = 0; i < len; ++i) {
ExtTypedProperty extProp = _properties.get(i);
String typePropId = extProp.getTypePropertyName();
SettableBeanProperty typeProp = otherProps.find(typePropId);
if (typeProp!= null) {
extProp.linkTypeProperty(typeProp);
}
extProps[i] = extProp;
}
return new ExternalTypeHandler(extProps, _nameToPropertyIndex, null, null);
}
<CHANGEE>
<FILEE>
<FILEB>
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
<CHANGES>
_externalTypeIdHandler = extTypes.build();
<CHANGEE>
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
// may need to disable vanilla processing, if unwrapped handling was enabled...
_vanillaProcessing = _vanillaProcessing && !_nonStandardCreation;
}
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
AnnotatedWithParams delegateCreator) throws JsonMappingException {
<FILEE>
<FILEB>
public static class Builder
{
private final ArrayList<ExtTypedProperty> _properties = new ArrayList<ExtTypedProperty>();
private final HashMap<String, Integer> _nameToPropertyIndex = new HashMap<String, Integer>();
public void addExternal(SettableBeanProperty property, TypeDeserializer typeDeser)
{
Integer index = _properties.size();
_properties.add(new ExtTypedProperty(property, typeDeser));
_nameToPropertyIndex.put(property.getName(), index);
_nameToPropertyIndex.put(<SCANS>nativeIds == null) {
_nativeIds = new TreeMap<Integer,Object>();
}
if (objectId != null) {
_nativeIds.put(_objectIdIndex(index), objectId);
}
if (typeId != null) {
_nativeIds.put(_typeIdIndex(index), typeId);
}
}
/**
* @since 2.3
*/
public Object findObjectId(int index) {
return (_nativeIds == null) ? null : _nativeIds.get(_objectIdIndex(index));
}
/**
* @since 2.3
*/
public Object findTypeId(int index) {
return (_nativeIds == null) ? null : _nativeIds.get(_typeIdIndex(index));
}
private final int _typeIdIndex(int i) { return i+i; }
private final int _objectIdIndex(int i) { return i+i+1; }
}
}